Well, come on.
That was the solution I found regarding what I understood of your problem.
You have a list of already populated professions and from the selections that the user makes in it you want to save in some kind of Storage.
Below is the code I made for all selected professions to be stored in a specific list.
angular.module('app', [])
.controller('testCtrl', function($scope, $http) {
$scope.objeto = {
profissoes: [
{
id: 1,
nome: 'prof1',
editando: false,
selecionado: false
},
{
id: 2,
nome: 'prof2',
editando: false,
selecionado: false
}
]
};
$scope.profSelect = new Array();
$scope.mudaLista = function(item){
if(item.selecionado) {
$scope.profSelect.push(item);
} else {
$scope.profSelect.splice(item, 1);
}
};
});
<!DOCTYPE html>
<html ng-app="app">
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
</head>
<body>
<div ng-controller="testCtrl as sic">
<label class="requerido">Profissoes</label>
<ul>
<li ng-repeat="item in objeto.profissoes" ng-class="{'editando':item.editando}">
<input type="checkbox" ng-model="item.selecionado" ng-checked="item.selecionado" ng-change="mudaLista(item)"/>{{item.nome}}
</li>
</ul>
<pre ng-bind="profSelect | json"></pre>
</div>
</body>
As you can see I used a ng-change
for each change (in the case of each check in) done the system adds/removes the profession from the specific list for selected items (profSelect).
From there you can store it wherever you want.
I hope I’ve helped :)
Somehow, I fail to say that what goes to the bank is just the ones selected. Simply item.checked is not enough.
– pnet