你可以看到我的模态中有一个对象列表,右侧有一个复选框。现在我想点击复选框,只检查一个项目。现在当我点击一个复选框时,会检查everthing。但主要的是我想要达到以下目的:
我想点击复选框并获取已检查的ID或团队。谢谢你的帮助!
这是我的模式:
<div class="col-md-12">
<ul class="list-group">
<li ng-repeat="team in teams" class="list-group-item">{{ team.allUserTeamName + " - " + team.allUserTeam }}
<label ng-repeat="(feature,enabled) in features">
<input type="checkbox" ng-model="features[feature]"/>
</label>
</li>
</ul>
</div>
<div class="modal-footer">
<div class="col-md-12">
<div class="row pad-team-selection-view">
<button class="btn btn-info"
ng-click="createGameplanWithSelectedMembers(team)">Spielplan
erstellen
</button>
</div>
</div>
</div>
{{features.value}}
这是我的控制器:
app.controller('modalCreateGameplanController', ['$scope', '$timeout', '$http', '$firebaseArray', '$firebaseObject', function($scope, $timeout, $http, $firebaseObject, $firebaseArray) {
$scope.selectUsers = 'Users';
$scope.$on('modal', function(event, args) {
var ref = firebase.database().ref("users");
var teams = $firebaseObject(ref);
$scope.features = {
value: false
};
teams.$loaded().then(function() {
$scope.teams = [];
angular.forEach(teams, function(key) {
$scope.teams.push({
allUserTeamName: key.firstname,
allUserTeam: key.team
});
});
});
});
}]);
答案 0 :(得分:1)
现在当我点击一个复选框时,会检查everthing。
每个team
的模型需要不同:
<div class="col-md-12">
<ul class="list-group">
<li ng-repeat="team in teams" class="list-group-item">
{{ team.allUserTeamName + " - " + team.allUserTeam }}
<label ng-repeat="(key,value) in features">
<input type="checkbox"
ng-model="team.key"
ng-change="onCheckboxChange(team, key)"
/>
</label>
</li>
</ul>
</div>
如果复选框为
,我现在该怎么办?true
或false
?
$scope.onCheckboxChange = function(team, key) {
console.log("Change for "+ team.allUserTeamName);
console.log(key +" changed to "+ team.key);
};