javascript - 在 Nativescript ListView 中显示项目

标签 javascript android typescript angular nativescript

我正在使用 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/

相关文章:

android - 如何连接布局 View 和 Activity

java - 键盘更换

android - StackMob 或 Server (MySql) 来处理用户帐户

javascript - 将 url 插入地址栏

javascript - 如何使我的页面重定向到其他项目中的页面而不影响通过 ui-router 的 session

javascript - 将 CSS 类用于逻辑是一种好习惯吗?

typescript - 带有 webpack 2.1.0-beta.25 的 tslint-loader

Javascript - 用于验证文档文件的正则表达式 - PDF、TXT、DOC

javascript - 错误 TS1112 : A class member cannot be declared optional

typescript 从 CDN 导入 .js