【发布时间】:2016-07-11 19:37:14
【问题描述】:
我正在使用 angular2 并且我正在绑定来自服务的数据,问题是当我加载数据时,我应该通过 id 过滤它,这是我应该做的:
<md-radio-button
*ngFor="#item of items_list"
*ngIf="item.id=1"
value="{{item.value}}" class="{{item.class}}" checked="{{item.checked}}"> {{item.label}}
</md-radio-button>
这是数据:
[
{ "id": 1, "value": "Fenêtre" ,"class":"md-primary" ,"label":"Fenêtre" ,"checked":"true"},
{ "id": 2, "value": "Porte Fenêtre" ,"class":"" ,"label":"Porte Fenêtre" }
]
顺便说一句,我希望只接受 id =1 的数据,但我看到了这个错误:
EXCEPTION: Template parse errors:
Parser Error: Bindings cannot contain assignments at column 14 in [ngIf item.id=1] in RadioFormesType1Component@10:16 ("
<md-radio-button
*ngFor="#item of items_list"
[ERROR ->]*ngIf="item.id=1"
value="{{item.value}}" class="{{item.class}}" checked="{{item.check"): RadioFormesType1Component@10:16
所以有什么建议一起使用 ngif 和 ngfor 吗?
【问题讨论】:
-
简单,甚至比答案更简单:过滤组件中的数据并将其传递给视图,根本不需要在视图中进行。
标签: json typescript angular angular2-directives angular2-services