[AngularJS] ng-ture-value & ng-false-value

When you have a checkbox, not necessary that just 'ture' & 'false', you might have 'yes', 'no', '1', '0':

There is how to use ng-true-value and ng-false-value with ng-checked for checkbox:

<input type="checkbox" 
    ng-model="checkbox" 
    ng-true-value="1" 
    ng-false-value="0" 
    ng-checked="checkbox == 1" />
$scope.$watch(function(){
    return $scope.checkbox;
}, function(){
    $scope.checkbox = Number($scope.checkbox);
    console.log($scope.checkbox, typeof $scope.checkbox);
},true);

 

posted @ 2018-02-03 04:38  Zhentiw  阅读(1049)  评论(0编辑  收藏  举报