选中控制器的复选框

时间:2015-09-15 15:06:05

标签: angularjs checkbox

我有角度控制器

$scope.event = {
  },
  type: {
    checked : false
  }
};

我像

一样使用它
<input id="show" name="type" type="checkbox" ng-model="event.type.checked">

当我重新加载页面时,我的复选框属性检查消失。我如何做条件,如果event.type.checked == true,则必须选中复选框,否则取消选中。请帮忙

2 个答案:

答案 0 :(得分:1)

检查演示:JSFiddle

此处有效:

angular.module('Joy', [])
    .controller('JoyCtrl', ['$scope', function ($scope) {
    $scope.event = {
        type: {
            checked: true
        }
    };
}]);

可能只是你的$scope.event有一个额外的大括号。

答案 1 :(得分:-1)

不太确定,但此文档可能对您有所帮助

https://docs.angularjs.org/api/ng/directive/ngChecked