你的问题是
ng-model
和
ng-checked
不能一起使用。
你应该可以
ng型号
,并将其绑在
boolean
属性。去除
ng已检查
从html和
ng型号
。
编辑:
下面显示了如何使用
ng-repeat
创建列表的步骤
<input>
其中每个部分都有自己的对象
$scope.questions[]
.完成后,您可以使用
ng型号
并将其绑定到
questions[i].active
直接地
var app = angular.module("MyApp", []);
var MyController = function($scope) {
$scope.questions = [{
questionId: 1,
active: false,
questionText: "First question"
}, {
questionId: 2,
active: true,
questionText: "Second question"
}];
$scope.questionStatusChange = function(currentQuestion) {
//currentQuestion.active = !currentQuestion.active;
console.log("Current Question Text: " + currentQuestion.questionText + "\nIs it clicked? " + currentQuestion.active);
}
}
app.controller(MyController, "[$scope, MyController]");
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
</head>
<body ng-app="MyApp">
<div ng-controller="MyController">
<div ng-repeat="question in questions">
<label class="switch">
<input
type="checkbox"
ng-model="question.active"
ng-change="questionStatusChange(question)" />
<span class="slider round"></span>
</label>
</div>
</div>
</body>
</html>