angular checkbox ng-model

程招
2023-12-01
 遇到的问题angular 里面的checkbox   的使用 
   当$scope.das=true or false 时  不起作用 
   $scope.das={
   value:true
 }  为对象时才起作用




<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title></title>
</head>
<script src="http://apps.bdimg.com/libs/angular.js/1.2.16/angular.min.js"></script>
<body>
<div ng-app="myApp" ng-controller="myCtrl">

  <label>Value1:
    <input type="checkbox" ng-model="des.value">
  </label><br/>
  <label>Value2:
    <input type="checkbox" ng-model="checkboxModel.value2"
           ng-true-value="'YES'" ng-false-value="'NO'">
  </label><br/>
  <tt>value1 = {{des.value}}</tt><br/>
  <tt>value2 = {{checkboxModel.value2}}</tt><br/>
</div>

<script>
  var app = angular.module('myApp', []);
  app.controller('myCtrl', function($scope) {
    $scope.name = "Beijing";
    $scope.das={
      value:true
    }
    $scope.checkboxModel = {
      value1 : true,
      value2 : 'YES'
    };
  });
</script>

</body>
</html>
 类似资料: