-1

i have an array of objects with one property Boolean. trying to bind this property to checkbox i snot working .

see below plunkr

https://plnkr.co/edit/dsQQCJrQD5kfOwcsCzze

i get and error

Can't bind to 'ngModel' since it isn't a known property of 'input'. 
Raas Masood
  • 1,475
  • 3
  • 23
  • 61

2 Answers2

1

You need to import FormsModule

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

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

WORKING DEMO

Sajeetharan
  • 216,225
  • 63
  • 350
  • 396
0

For checkbox input you can use [checked] instead of [(ngModel)] Also, you can use (change) instead of ([ngModelChange)]

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

Checkout the plunker here

Vandesh
  • 6,368
  • 1
  • 26
  • 38
  • if i do this the "select" method is not called. – Raas Masood Oct 31 '17 at 17:41
  • i am trying to unselect the checkbox when it is selected public select(item){ alert(item.name); item.selected = false; } – Raas Masood Oct 31 '17 at 17:42
  • You need to use `(change)` for that. Checkout the updated answer and the updated plunker. – Vandesh Oct 31 '17 at 17:44
  • check this out https://plnkr.co/edit/WdtFF96B5GJScFYMQFzG the "selected" property is false it should be true because we recently checked it. – Raas Masood Oct 31 '17 at 17:48
  • I am checking if it's a trivial problem in your code, but I think that is not what your original question was. Your original question gets resolved by using `(change)` and `[checked]`. You can verify by the alert being executed and if you set any of the `selected` values to true, the checkbox will already be checked. – Vandesh Oct 31 '17 at 17:57
  • I am checking if it's a trivial problem in your code, but I think that is not what your original question was. Your original question gets resolved by using `(change)` and `[checked]`. You can verify by the alert being executed and if you set any of the `selected` values to true, the checkbox will already be checked. – Vandesh Oct 31 '17 at 17:57