2017-04-11 34 views
0

您好我在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]元素。

+1

你的代碼看起來不錯?你使用什麼版本的nativescript? –

+1

是你使用的是什麼版本,如果你使用的是RC(意思是Angular 4),那麼'