Is there a way to retrieve the ID of a checked checkbox item in a list when a button is clicked, and then store those items in a variable or array for future use?
Sample HTML:
<input id="btnCheck" type="button" value="Next" ng-click="addSelected()" />
<div ng-controller="movieController">
<ul>
<li ng-repeat="movie in Movies">
<input id="chkBox-{{ movie.MovieID }}"
type="checkbox"
ng-checked="selection.indexOf(movie.MovieID) > -1"
ng-click="toggleSelection(movie.MovieID)"
/>
</li>
</ul>
</div>
Javascript:
$scope.AddSelected = function () {
var selected = $scope.selection
console.log(selected);
}
$scope.selection = [];
$scope.toggleSelection = function toggleSelection(movie) {
var idx = $scope.selection.indexOf(movie);
if (idx > -1) {
$scope.selection.splice(idx, 1);
}
else {
$scope.selection.push(movie);
}
};