Reputation: 465
I'm trying to repeat a nested object and I have a checkbox with a value of true or false.
Here's my code:
<accordion-group
*ngFor='let brand of products'>
<div *ngFor='let product of brand.products'>
<div>
<input type="checkbox" id="{{product.name}}" ngControl="{{product}}" ([ngModel])="product.checked">
<label
attr.for="{{product.name}}"
id="{{product.description}}"
class="{{product.description}}"
(click)="onCheck(model)">
</label>
</div>
</p>
</div>
</accordion-group>
Plunker: http://plnkr.co/edit/IItxHiXkpocUjLG6NhMy?p=preview -- see that the checkbox doesn't check when the quantity value is updated. I can't get ngModel to work correctly.
Upvotes: 0
Views: 3289
Reputation: 86740
ngControl
should be fromControlName
according to angular2 RC.5
([ngModel]) should be [(ngModel)]
or used as different one like [ngModel]
and (ngModel)
.
better to use property Binding using [ ]
while binding id ,name etc dynamicaly as in your case use
use
[id]="product?.name"
instead ofid="{{product.name}}"
use
[attr.for]="product?.name"
instead ofattr.for="{{product.name}}"
seems Rest is fine everything, if still having same issue please reproduce your problem on plunker and post it.
Upvotes: 2
Reputation: 657248
This is invalid
([ngModel])
and should be
[(ngModel)]
It's called "banana in a box", not "box in a banana" ;-)
Upvotes: 1