我试图在Nativescript Angular中播放ListView,我无法渲染定义的模板 . 我的ListView显示[object Object]而不是模板 . 我总是得到那个结果 . 如果我的数组中的项是String,则文本显示在该行上,如果它是一个对象,它坚持不显示我的模板并显示[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>
4 回答
我遇到了同样的问题,我通过在“nativescript-angular / platform”中包含import 来修复它;在包含列表的模块中 .
使用NativeScript 4.1.1:
你需要在app.module中这个:
但是在引用ListView的特定模块中,您需要导入:
我正在使用RadListView,但我认为这也适用于普通的ListView .
至于现在,您需要从“nativescript-angular / common”导入NativeScriptCommonModule到包含模块 .
在NativeScript 4.1.0中,您必须包含此模块
并将其添加到导入