我正在使用 Angular 2 学习 Nativescript,并尝试从 https://randomuser.me
API 获取随机用户数据。我无法在 ListView 中仅显示 10 个随机用户的名称。它只在 ListView 中显示 10 个空白列表项。
这是我的 app.component.ts
import {Component} from "@angular/core";
import {Http, HTTP_PROVIDERS, Response} from "@angular/http";
import {Observable} from "rxjs/Rx";
@Component({
selector: "my-app",
templateUrl: "app.component.html",
providers: [HTTP_PROVIDERS]
})
export class AppComponent {
public names: Observable<Array<Object>>;
constructor(public http: Http){
}
public onTap(){
this.getData()
.subscribe(
(res) => {
this.names = res.json().results;
}
);
}
public getData(){
return this.http.get('https://randomuser.me/api/?results=10');
}
这是我的html模板文件
<StackLayout>
<Button text="GET" (tap)="onTap()"></Button>
<ListView [items]="names">
<template let-item="item">
<Label (text)="item.gender" textWrap="true"></Label>
</template>
</ListView>
</StackLayout>
非常感谢任何帮助。
最佳答案
更改<Label (text)="item.gender" textWrap="true"></Label>
到
<Label [text]="item.gender" textWrap="true"></Label>
关于javascript - 在 Nativescript ListView 中显示项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38162438/