I have a function in ng-change that executes every time the checkbox is checked (manually).
Now I want the checkboxes to be pre-checked at boot time, and the function inside ng-change also executed (at boot).
What are some of the approaches I can take to achieve this?
You do not need to do this, your model will automatically do this, say
$ scope.customer = client;
<input type='checkbox' ng-model='customer.active' /> Is Active
It will automatically take care
, onChange, ng-init
onLoad onChange, :
$scope.onLoad = function(params) { // do some init functionality and call onChange functionality onChange(); } $scope.onChange = function(value) { // do function when a combobox is chaned }
HTML-
<div ng-init="onLoad()"> <input type='checkbox' ng-model='someModel' ng-change="('1')"/> Is one <input type='checkbox' ng-model='someModel' ng-change="('2')"/> Is two <input type='checkbox' ng-model='someModel' ng-change="('3')"/> Is three </div>
ng-change , , angular docs . , ng-change, , . , .
ng-change
$scope.$watch("myModel", function(newValue, oldValue){ // do something });