【发布时间】:2017-04-23 03:04:54
【问题描述】:
我正在尝试在 Nativescript + Angular 中播放 ListView,但无法呈现定义的模板。我的 ListView 显示 [object Object] 而不是模板。我总是得到这样的结果。如果我的数组中的项目是字符串,则文本显示在行上,如果是对象,则坚持不显示我的模板并显示 [object Object]。
我得到的结果是这样的:
下面是我的代码
eventos.component.ts
import {Component, OnInit, ChangeDetectionStrategy, Input} from '@angular/core';
@Component({
selector: "PrincipalEventosListView",
templateUrl: "pages/principal/eventos/eventos.component.html",
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class PrincipalEventosComponent {
public registros: Array<any>;
constructor() {
this.registros = [];
this.registros.push({tipo: "Teste 1"});
this.registros.push("String no lugar de objeto.");
this.registros.push({tipo: "Teste 3"});
this.registros.push(123);
this.registros.push({tipo: "Teste 4"});
}
}
eventos.component.html
<GridLayout>
<ListView [items]="registros">
<template let-item="item">
<Label [text]="item.tipo"></Label>
</template>
</ListView>
【问题讨论】:
-
这里的问题应该用英语...
-
@DawidZbiński 我现在翻译了
-
查看您的代码,这应该可以按预期工作。将其视为参考github.com/NativeScript/nativescript-sdk-examples-ng/blob/… 还检查您的 package.json 版本的所有角度相关依赖项并重建您的应用程序。
标签: angular nativescript angular2-nativescript