【问题标题】:NativeScript Angular ListView Rendering [object Object]NativeScript Angular ListView 渲染 [object Object]
【发布时间】: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>

【问题讨论】:

标签: angular nativescript angular2-nativescript


【解决方案1】:

目前,您需要将 NativeScriptCommonModule 从 'nativescript-angular/common' 导入到包含模块。

【讨论】:

    【解决方案2】:

    使用 NativeScript 4.1.1:

    你在 app.module 中确实需要这个:

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

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

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

    我使用的是 RadListView,但我认为这可能也适用于普通的 ListView。

    【讨论】:

      【解决方案3】:

      在 NativeScript 4.1.0 中你必须包含这个模块

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

      并将其添加到导入中

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

      【讨论】:

        【解决方案4】:

        我遇到了同样的问题,我通过包含 import { NativeScriptModule } from "nativescript-angular/platform" 来解决它;在包含列表的模块中。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2017-11-13
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2021-07-21
          • 1970-01-01
          • 2012-04-16
          • 2018-07-08
          相关资源
          最近更新 更多