[英]How to access the static variable in ngFor in angular2
I have loop which access the component static variable.. If I use "let person of persons()" it doesnt work. 我有循环访问组件静态变量..如果我使用“让人的人()”它不起作用。 Here persons method return multiple person.. getting "TypeError: self.context.persons is not a function" error
这里person方法返回多个人..得到“TypeError:self.context.persons不是函数”错误
static persons: Array<PersonDirective> = [];
get persons(){
return PersonInvolvedComponent.persons;
}
html is below html在下面
<person-directive *ngFor="let person of persons(); #idx = index" (remove) = "removePerson(idx)">
</person-directive>
Change your template to 将模板更改为
<person-directive *ngFor="let person of persons; let idx = index" (remove) = "removePerson(idx)">
</person-directive>
Getters are accessed as properties, not methods. Getters作为属性而不是方法访问。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.