[英]AngularJS - Checkbox get the id from checked object
as you can see I have a list of objects in my modal with a checkbox on the right side. 如您所见,我的模态中有一个对象列表,右侧有一个复选框。 Now I want to click the checkbox and only check one single item. 现在,我想单击复选框,仅选中一个项目。 Right now when I click on one checkbox, everthing gets checked. 现在,当我单击一个复选框时,所有内容都会被选中。 But the main thing is that I want to archieve the following: 但是最主要的是,我想归档以下内容:
I want to click on the checkbox and get the id or the team that is checked. 我想单击复选框并获取ID或选中的团队。 Thank you for your help! 谢谢您的帮助!
This is my modal: 这是我的模态:
<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}}
This is my controller: 这是我的控制器:
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
});
});
});
});
}]);
Right now when I click on one checkbox, everthing gets checked. 现在,当我单击一个复选框时,所有内容都会被选中。
The model needs to be different for each team
: 每个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>
How do I now if the checkbox is
true
orfalse
? 现在,如果复选框为true
或false
我该如何处理?
$scope.onCheckboxChange = function(team, key) {
console.log("Change for "+ team.allUserTeamName);
console.log(key +" changed to "+ team.key);
};
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.