首页 文章

NativeScript Angular ListView渲染[object Object]

提问于
浏览
3

我试图在Nativescript Angular中播放ListView,我无法渲染定义的模板 . 我的ListView显示[object Object]而不是模板 . 我总是得到那个结果 . 如果我的数组中的项是String,则文本显示在该行上,如果它是一个对象,它坚持不显示我的模板并显示[object Object] .

我得到的结果是这样的:

enter image description here

以下是我的代码

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 回答

  • 0

    我遇到了同样的问题,我通过在“nativescript-angular / platform”中包含import 来修复它;在包含列表的模块中 .

  • 0

    使用NativeScript 4.1.1:

    你需要在app.module中这个:

    import { NativeScriptModule } from "nativescript-angular/nativescript.module";
    

    但是在引用ListView的特定模块中,您需要导入:

    import { NativeScriptUIListViewModule } from "nativescript-ui-listview/angular";
    

    我正在使用RadListView,但我认为这也适用于普通的ListView .

  • -1

    至于现在,您需要从“nativescript-angular / common”导入NativeScriptCommonModule到包含模块 .

  • 4

    在NativeScript 4.1.0中,您必须包含此模块

    import { NativeScriptModule } from "nativescript-angular/nativescript.module";
    

    并将其添加到导入

    @NgModule({
      ...
      imports: [NativeScriptModule],
      ...
    })
    

相关问题