2017-02-14 15 views
1

配列のデータをHTMLテーブルにレンダリングしたい。ここに私のモデルです:ng-containerの配列からデータをレンダリングする方法Angular 2?

export class Section { 
    public id :number; 
    public name: string; 
    constructor(id: number, theName: string) { 
     this.id = id; 
     this.name = theName; 
    } 
} 

私はそれをインポートして、コンポーネントでそれを埋める:

import { Section } from "../models/registerSection.model"; 

配列の宣言:

sectionList: Array<Section>; 

配列がコンストラクタに充填されています

this.sectionList = [new Section(1, "A"), 
     new Section(2, "B*"), 
     new Section(3, "C"), 
     new Section(4, "D")]; 

これは私がレンタルしようとしている方法ですテンプレート内のデータ:

 <ng-container *ngFor='let data of Section'> 
      <tr> 
       <td colspan="7">{{data.name}}</td> 
      </tr> 
     </ng-container> 

テーブルが空です。 DOMでは、次のように表示されます。

<!--template bindings={ 
    "ng-reflect-ng-for-of": null 
}--> 

私は間違っていますか?デバッグでは、配列にデータが含まれていることがわかります。

答えて

2

それは次のようになります。

<ng-container *ngFor='let data of sectionList'> 

今、あなたはそのモデルのインスタンスであるSectionモデル、ないsectionListを反復処理しようとしています。

+1

はい!ありがとうございました....私は気付かなかった。私は角度の研究に絡み合っている... – Seva

関連する問題