如何在angular2中的ngFor中访问静态变量 [英] How to access the static variable in ngFor in angular2

查看:47
本文介绍了如何在angular2中的ngFor中访问静态变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我具有访问组件静态变量的循环.如果我使用"letter of person()",它将不起作用.这里的persons方法返回多个person ..收到"TypeError:self.context.persons不是函数"错误

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

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

html在下面

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

推荐答案

将模板更改为

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

字母是作为属性而不是方法访问​​的.

Getters are accessed as properties, not methods.

这篇关于如何在angular2中的ngFor中访问静态变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆