在NativeScript+;Angula2应用

在NativeScript+;Angula2应用,nativescript,Nativescript,我正在尝试显示带有ngFor的标签列表。 皮带是一种简单的数据结构。其中的每一项都有一个主题 我得到一个错误: JS:Error:SilabusComponent类SilabusComponent-内联模板中的错误:2:64由以下原因引起: 无法读取未定义的属性“subject” 似乎它不知道这个项目。有什么想法吗 以下是部件分解器: @Component({ selector: "kbm-silabus", template: ` <StackLayout>

我正在尝试显示带有ngFor的标签列表。 皮带是一种简单的数据结构。其中的每一项都有一个主题

我得到一个错误: JS:Error:SilabusComponent类SilabusComponent-内联模板中的错误:2:64由以下原因引起: 无法读取未定义的属性“subject”

似乎它不知道这个项目。有什么想法吗

以下是部件分解器:

@Component({
   selector: "kbm-silabus",
   template: `
      <StackLayout>
        <Label ngFor="let item of silabusList; let i=index"                    [text]="item.subject"></Label> 
    </StackLayout>
   `
})

export class SilabusComponent {
    private sub: any;
    silabusList: Array<Silabus>;

    ngOnInit() {
      this.page.actionBar.title = "KBM School";
      this.sub = this.route.params.subscribe(params => {
        this.id = params['id'];
        this.silabusList = [];
        this.silabusSubjects = [];

        BELTS[this.id].silabus.forEach((item, index) => {
            this.silabusList.push(new Silabus(item.subject, item.content));
            console.log(item.subject);
        })
      });
    }

    ngOnDestroy() {
      this.sub.unsubscribe();
    }

}
@组件({
选择器:“kbm silabus”,
模板:`
`
})
导出类组件{
私人分包商:任何;
列表:数组;
恩戈尼尼特(){
this.page.actionBar.title=“KBM学校”;
this.sub=this.route.params.subscribe(params=>{
this.id=params['id'];
this.buslist=[];
this.subjects=[];
皮带[this.id].silabus.forEach((项目,索引)=>{
this.silabusList.push(新的Silabus(item.subject,item.content));
console.log(item.subject);
})
});
}
恩贡德斯特罗(){
此.sub.取消订阅();
}
}

您错过了ngFor前面的asterix叹息,这非常重要,否则您只能使用完整语法的ngFor模板。在NativeScript项目中,使用*ngFor语法

e、 g


基本上,这就是如何使用不同的语法规则获得相同的输出:

<!-- Examples (A) and (B) are the same -->

<!-- (A) *ngFor -->
<Label *ngFor="let hero of heroes" [text]="hero"></Label >

<!-- (B) ngFor with template -->
<template ngFor let-hero [ngForOf]="heroes">
  <Label [text]="hero"></Label >
</template>

在本报告中,您可以找到示例,即如何在NativeScript Angular2项目中使用ngFor指令
<!-- Examples (A) and (B) are the same -->

<!-- (A) *ngFor -->
<Label *ngFor="let hero of heroes" [text]="hero"></Label >

<!-- (B) ngFor with template -->
<template ngFor let-hero [ngForOf]="heroes">
  <Label [text]="hero"></Label >
</template>