Reputation: 32788
I have:
<input ng-model="answer.response" type="checkbox" />
When data is fetched from the server there will initially be no value for answer.response.
Is there a way I can make this default to false?
Upvotes: 1
Views: 53
Reputation: 52847
The checkbox is bound to the model answer.response.
If you want to default it to false, then set answer.response to false in your controller.
app.controller('ctrl', function($scope) {
$scope.answer = { response: false };
});
HTML:
<div ng-controller='ctrl'>
<input ng-model="answer.response" type="checkbox" />
</div>
Initalization code belongs in the controller. ng-init is only appropriate for aliasing special properties of ng-repeat.
Upvotes: 1
Reputation: 7475
check this out: use ng-init
<div ng-init="options={};options.selected=false">
<input type="checkbox"
ng-checked="options.selected"
ng-model="options.selected"/>
</div>
Upvotes: 2