簡體   English   中英

如何在angular2中訪問ngFor中的靜態變量

[英]How to access the static variable in ngFor in angular2

我有循環訪問組件靜態變量..如果我使用“讓人的人()”它不起作用。 這里person方法返回多個人..得到“TypeError:self.context.persons不是函數”錯誤

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作為屬性而不是方法訪問​​。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM