ngModel无法处理绑定到对象数组的复选框

时间:2017-10-31 17:33:19

标签: javascript angular

我有一个具有一个属性Boolean的对象数组。尝试将此属性绑定到复选框i snot working。

见下面的plunkr

https://plnkr.co/edit/dsQQCJrQD5kfOwcsCzze

我得到并且错误

Can't bind to 'ngModel' since it isn't a known property of 'input'. 

2 个答案:

答案 0 :(得分:0)

您需要导入 FormsModule

import { FormsModule, ReactiveFormsModule } from '@angular/forms'

@NgModule({
imports: [ BrowserModule ,FormsModule],
declarations: [ App ],
bootstrap: [ App ]
})

<强> WORKING DEMO

答案 1 :(得分:0)

对于复选框输入,您可以使用[checked]代替[(ngModel)] 此外,您可以使用(change)代替([ngModelChange)]

<input class="checkbox binning-checkbox" type="checkbox"  
            (change)="select(item)" [checked]="item.selected">

结帐the plunker here

相关问题