无法绑定到'为',因为它不是一个已知的原生属性angular2 [英] Can't bind to 'for' since it isn't a known native property angular2
问题描述
我要动态地创建一个复选框列表,所以我已经使用* ngFor遍历所有对象的数组是工作的罚款,直到迭代。当我设置的在标签标记
属性值的问题发生。角有抛出错误:
无法绑定到'为',因为它不是一个已知的原生属性angular2
块引用>< DIV * ngFor =#一批batch_array的>
<标签={{batch.id}}><输入类型=复选框[值] =batch.idID ={{batch.id}}
(点击)=batchSelectedEevent(batch.id)/> {{batch.batch_name}}
< /标签>
< / DIV>这是我plnkr示值误差: http://plnkr.co/edit/ aAQfWvHc7h7IBuYzpItO?p = preVIEW
什么是错在这里我的code?
解决方案在默认情况下角使用属性绑定,但
标签
没有属性为
。告诉角度明确使用属性绑定,使用来代替:[attr.for] =someField
或
attr.for ={{someField}}
代替。
I have to Create a list of checkboxes dynamically so i have used *ngFor to iterate the array of objects everything is working fine till iteration. the problem is occured when i set the value of
for
attribute in the label tag. angular has throw the error :Can't bind to 'for' since it isn't a known native property angular2
<div *ngFor="#batch of batch_array"> <label for="{{batch.id}}"><input type="checkbox" [value]="batch.id" id="{{batch.id}}" (click)="batchSelectedEevent(batch.id)" /> {{batch.batch_name}} </label> </div>
here is my plnkr showing error : http://plnkr.co/edit/aAQfWvHc7h7IBuYzpItO?p=preview
whats wrong here in my code ?
解决方案Angular by default uses property binding but
label
doesn't have a propertyfor
. To tell Angular explicitly to use attribute binding, use instead:[attr.for]="someField"
or
attr.for="{{someField}}"
instead.
这篇关于无法绑定到'为',因为它不是一个已知的原生属性angular2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!