2016-10-21 5 views
1

구성 변수 정적 변수에 액세스하는 루프가 있습니다. "person person()"을 사용하면 작동하지 않습니다. 여기에 사람의 방법은 점점 .. 여러 사람을 반환 : 오류 "형식 오류 함수가 아닌 self.context.persons을"angular2의 ngFor에서 static 변수에 액세스하는 방법

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

아마도 'person of let persons()'에서'persons '뒤에 오는 중괄호가 문제일까요? – rinukkusu

+1

그럴 수 있습니다. 'persons()'를 사용하면'persons() '를 사용하여 호출 할 수 없습니다 –

답변

3

<person-directive *ngFor="let person of persons; let idx = index"  (remove) = "removePerson(idx)"> 
</person-directive> 
에 템플릿을 변경 이하

게터는 메서드가 아닌 속성으로 액세스됩니다.

관련 문제