2016-10-21 6 views
1

私はコンポーネントの静的変数にアクセスするループを持っています。 "人の人を呼ぶ"を使用すると動作しません。ここでは人の方法は、取得..複数の人物を返す:エラー "例外TypeError機能ではありませんself.context.personsを"angular2のngForで静的変数にアクセスする方法

static persons: Array<PersonDirective> = [];  
get persons(){ 
    return PersonInvolvedComponent.persons; 
} 

htmlが

<person-directive *ngFor="let person of persons(); #idx = index"  (remove) = "removePerson(idx)"> 
    </person-directive> 
+0

なぜこれが機能しないのかわかりません。 '#idx = index'は無効です。それは 'let idx = index'でなければなりません。 –

+3

問題は、人の人()の '人 'の後の中カッコですか? – rinukkusu

+1

さて、 'persons()'を呼び出すことはできません 'persons()' –

答えて

3

<person-directive *ngFor="let person of persons; let idx = index"  (remove) = "removePerson(idx)"> 
</person-directive> 
にテンプレートを変更するには、以下のです

ゲッターはメソッドではなくプロパティとしてアクセスされます。

関連する問題