Issue
I have a checkbox and i want to set value of checkbox as false when it is unchecked frst time. How to do that in angular js?
<div class="col-xs-6 col-xs-offset-4 col-sm-6 col-sm-offset-4 col-md-7 col-md-offset-3 col-lg-7 col-lg-offset-3 controls test-check">
<input
type="checkbox"
id="checkbox-1-1"
class="regular-checkbox"
ng-true-value="true"
ng-false-value="false"
ng-checked="addUser.isAllOrgSelected"
ng-model="addUser.isAllOrgSelected">
<label for="checkbox-1-1"></label>
<label class="label-all">{{::'label.all'|translate}}</label>
</div>
Solution
I have a checkbox and i want to set value of checkbox as false when it is unchecked frst time. How to do that in angular js?
that is actually the default behavior
angular.module('myApp', [])
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="myApp">
<label>
<input type="checkbox" ng-model="checked"> my checkbox
</label> Checked: {{ checked | json}}
</div>
edit:
If you want to set the value of your model to false before anyone interacts with your checkbox, you could do so in a ngController:
angular.module('myApp', [])
.controller('ctrl', function() {
var vm = this
vm.checked = false
})
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="myApp">
<div ng-controller="ctrl as vm">
<label>
<input type="checkbox" ng-model="vm.checked"> my checkbox
</label> Checked: {{ vm.checked | json}}
</div>
</div>
Answered By - jbe
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.