[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);
原文地址:https://www.cnblogs.com/Answer1215/p/8408490.html