加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

不能绑定到’for’,因为它不是已知的本机属性angular2

发布时间:2020-12-17 08:06:52 所属栏目:安全 来源:网络整理
导读:我必须动态地创建一个复选框列表,所以我使用* ngFor来迭代对象的数组,一切都正常工作,直到迭代。当我在label标签中设置for属性的值时,会出现问题。角已经抛出错误: Can’t bind to ‘for’ since it isn’t a known native property angular2 新的错误
我必须动态地创建一个复选框列表,所以我使用* ngFor来迭代对象的数组,一切都正常工作,直到迭代。当我在label标签中设置for属性的值时,会出现问题。角已经抛出错误:

Can’t bind to ‘for’ since it isn’t a known native property angular2

新的错误消息

Unhandled Promise rejection: Template parse errors: Can’t bind to ‘for’ since it isn’t a known property of ‘label’.

<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>

这是我的plnkr显示错误:http://plnkr.co/edit/aAQfWvHc7h7IBuYzpItO?p=preview

在我的代码中有什么错误?

更新

在Angular2最终[for] =“xxx”应该正常工作。他们从一个别名添加到htmlFor。

原版的

Angular默认使用属性绑定,但label没有属性。要明确指出Angular使用属性绑定,请改用:

[attr.for]="someField"

要么

attr.for="{{someField}}"

代替。

这些也是工作,因为htmlFor是属性被反映到。

[htmlFor]="someField"
htmlFor="{{someField}}"

在Angular2 RC.6中,添加了一个别名,以便现在也可以工作:

[for]="someField"

要么

for="{{someField}}"

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读