码迷,mamicode.com
首页 > Web开发 > 详细

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

时间:2018-02-03 13:23:23      阅读:439      评论:0      收藏:0      [点我收藏+]

标签:func   scope   $watch   body   when   checkbox   div   col   fun   

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

标签:func   scope   $watch   body   when   checkbox   div   col   fun   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!