2016-05-02 8 views
1

ngForディレクティブを使用して子オブジェクトを親オブジェクトに渡す方法。ngForディレクティブを使用して親オブジェクトに子オブジェクトIDを渡す方法

動的なtdとtr(Angular 2 beta.17を使用)を実装する必要があります。 以下のコードを試しましたが、動作しません。

エラー:

テンプレート解析エラー: レクサーエラー:式の列18で切断していない引用[AItemは[ '{{header.id]

データ:

headerList:[ 
       {"id":"id1", "label":"ID1"}, 
       {"id":"id2", "label":"ID2"}, 
       {"id":"id3", "label":"ID3"}, 
      ] 

resp =[ 
     { 

     "id1": "1", 
     "id2": "1", 
     "id3": "1", 
     "id4": "1", 
     "id5": "1" 
     }, 
     { 

     "id1": "2", 
     "id2": "2", 
     "id3": "2", 
     "id4": "2", 
     "id5": "2" 
     }, 
     { 

     "id1": "3", 
     "id2": "3", 
     "id3": "3", 
     "id4": "3", 
     "id5": "3" 
     }, 
     { 

     "id1": "4", 
     "id2": "4", 
     "id3": "4", 
     "id4": "4", 
     "id5": "4" 
     } 
] 

コード:

<table class="table table-striped"> 
    <thead> 
     <tr> 
      <th *ngFor="let header of headerList"> 
        {{header.label}} 
      </th> 
     </tr> 
    </thead> 
    <tbody> 
     <tr *ngFor="let aItem of resp"> 
      <td *ngFor="let header of headerList"> 
       {{aItem['{{header.id}}']}} 
      </td> 
     </tr> 
    </tbody> 
</table> 
+0

本文にはヘッダーのリストがありますか? –

答えて

0

{{}}の内部には使用できません{{}}。あなたが実際に何を達成しようとしているのか分かりませんが、これはあなたが望むものかもしれません:

{{aItem[header.id]}} 
+1

ありがとう、それは動作します – user1127804

+0

喜んで聞いてください。これで問題が解決した場合は、アップ/ダウンボタンの下にある白いチェックマークをクリックして回答を受け入れるようにしてください。 –

関連する問題