I have called a function on ng-checked and through that function it is getting decided whether checkbox will be checked or not. But the function is not getting called at the load of page.
html –
<label>
<input type="checkbox" name="status1" id="status1" ng-click="vm.updateStatus('processing')" ng-checked="vm.isSelectedStatus('processing')"> In progress
</label>
JS(controller) –
var vm = this;
vm.isSelectedStatus = isSelectedStatus;
vm.tasksStatus = ["processing", "finished", "failed"];
function isSelectedStatus(status) {
return vm.tasksStatus.indexOf(status) > -1;
}
function updateStatus(status) {
var index;
index = vm.tasksStatus.indexOf(status);
if(index === -1) {
vm.tasksStatus.push(status);
} else {
vm.tasksStatus.splice(index, 1)
}
}
Source: AngularJS
from Angular Questions https://angularquestions.com/2017/10/10/why-function-on-ng-checked-is-not-getting-called/
via @lzomedia #developer #freelance #web #lzomedia.com
No comments:
Post a Comment