您好我在NativeScript中使用Angular2時遇到了ListView問題。[Angular2] [NativeScript]模板標籤在ListView中不起作用
在我的指令我有對象的數組
export class Room {
constructor(
public name: string,
public tag: string
){ }
}
import { Page } from "ui/page";
import { Component, OnInit, EventEmitter, Output, ChangeDetectionStrategy } from '@angular/core';
import { NativeScriptRouterModule } from "nativescript-angular/router";
import { NativeScriptModule } from "nativescript-angular/nativescript.module";
@Component({
moduleId: module.id,
selector: 'rooms-list',
templateUrl: "./template.html",
providers: [RoomService],
changeDetection: ChangeDetectionStrategy.OnPush
})
export class RoomsListComponent implements OnInit {
public items: Array<Room> = [];
listLoaded = false;
load() {
for (let i = 0; i < 200; i++) {
this.items.push(
new Room("room " + i, "tag " + i)
);
}
}
ngOnInit(): void {
this.load();
}
onTap(name){
console.log('taped: '+name);
}
}
在我的模板,我使用的ListView
<ListView [items]="items" id="roomsList">
<template let-item="item">
<StackLayout>
<Label [text]='"[" + item.tag +"] " + item.name'></Label>
</StackLayout>
</template>
</ListView>
但它看起來像模板標籤犯規存在,名單隻包含 [object Object]
元素。
你的代碼看起來不錯?你使用什麼版本的nativescript? –
是你使用的是什麼版本,如果你使用的是RC(意思是Angular 4),那麼''已經改成'',類似的問題在這裏:http://stackoverflow.com/a/43074761/3801632 –
@ VladimirAmiorkov ng模板仍然不起作用。 即時通訊使用nativescript 2.5 –