AngularJS - 复选框从选中的对象中获取 id
AngularJS - Checkbox get the id from checked object
如您所见,我的模态中有一个对象列表,右侧有一个复选框。现在我想单击复选框并只选中一个项目。现在,当我单击一个复选框时,所有内容都会被选中。但最主要的是我想实现以下目标:
我想点击复选框并获取 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
});
});
});
});
}]);
Right now when I click on one checkbox, everthing gets checked.
每个模型需要不同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
or false
?
$scope.onCheckboxChange = function(team, key) {
console.log("Change for "+ team.allUserTeamName);
console.log(key +" changed to "+ team.key);
};
如您所见,我的模态中有一个对象列表,右侧有一个复选框。现在我想单击复选框并只选中一个项目。现在,当我单击一个复选框时,所有内容都会被选中。但最主要的是我想实现以下目标:
我想点击复选框并获取 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
});
});
});
});
}]);
Right now when I click on one checkbox, everthing gets checked.
每个模型需要不同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
?
$scope.onCheckboxChange = function(team, key) {
console.log("Change for "+ team.allUserTeamName);
console.log(key +" changed to "+ team.key);
};