This is probably easy and I'm missing something very basic. I'm generating several md-checkbox
s using ng-repeat
over an array. How can I clear this array without breaking the $digest
cycle? selectedItems
is an array of objects which holds data based on the checkboxes the user checked.
<div id="container">
<span class="network-wrapper" ng-repeat="item in $ctrl.dataSource">
<md-checkbox ng-model="$ctrl.networksCheckboxes[item.id]"
ng-checked="$ctrl.exists(item, $ctrl.selectedItems)"
ng-change="$ctrl.toggle(item, $ctrl.selectedItems)">
{{ item.name }}
</md-checkbox>
</span>
<button class="btn btn-danger" ng-click="$ctrl.reset()">Reset</button>
</div>
JS:
public toggle (item, list) {
var idx = list.indexOf(item);
if (idx > -1) {
list.splice(idx, 1);
}
else {
list.push(item);
}
};
public exists (item, list) {
return list.indexOf(item) > -1;
};
public reset(){
this.selectedItems.length = 0; //Error: [$rootScope:infdig] 10 $digest() iterations reached. Aborting!
}