首页 > Web开发 > 详细

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

时间:2018-02-03 11:33:36      阅读:304      评论:0      收藏:0      [点我收藏+]

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);

 

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

原文:https://www.cnblogs.com/Answer1215/p/8408490.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!