无法绑定到'为',因为它不是一个已知的原生属性angular2 [英] Can't bind to 'for' since it isn't a known native property angular2

查看:132
本文介绍了无法绑定到'为',因为它不是一个已知的原生属性angular2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要动态地创建一个复选框列表,所以我已经使用* ngFor遍历所有对象的数组是工作的罚款,直到迭代。当我设置的在标签标记属性值的问题发生。角有抛出错误:


  

无法绑定到'为',因为它不是一个已知的原生属性angular2


 < D​​IV * 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 property for. To tell Angular explicitly to use attribute binding, use instead:

[attr.for]="someField"

or

attr.for="{{someField}}"

instead.

这篇关于无法绑定到'为',因为它不是一个已知的原生属性angular2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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