Reputation: 1020
I want to add checked and unchecked attribute to the checkbox which is in a table I tried to using it via jquery in angularjs
$('#chksitecolumn_' + item.Id).attr('checked', true)
Here item.Id
is the id which I am iterating and binding it on ng-model
.
and also tried it using angularjs
var element = angular.element('#chksitecolumn_' + item.Id);
element.attr('checked', 'checked');
but it is not working
Here is my checkbox
<input type="checkbox" class="test" id="chksitecolumn_{{item.Id}}"
ng-model="selected[item.Id]"/>
I am passing an ID as a key using ng-model
I want to know that can we check uncheck checkbox except using ng-model
?
Upvotes: 0
Views: 218
Reputation: 3618
To check/uncheck you can use ng-checked
directive (documentation) :
<input type="checkbox" class="test" id="chksitecolumn_{{item.Id}}"
ng-checked="checked[item.Id]" />
Note that you should not use ng-checked
with ng-model
together:
Note that this directive should not be used together with
ngModel
, as this can lead to unexpected behavior.
Upvotes: 1