I'm trying to use a Array
in a input[type=checkbox]
with Angle 1, but I was not successful.
angular.module('app', [])
.controller("Ctrl", function ($scope){
$scope.campos = [{nome: "Brasil"}, {nome: "Argentina"}, {nome: "Paraguai"}];
$scope.campos_selecionados = [];
})
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.9/angular.min.js"></script><divng-app="app" ng-controller="Ctrl">
<label ng-repeat="campo in campos">
<input type="checkbox"
ng-true-value="{{ campo }}"
ng-false-value="undefined"
ng-model="campos_selecionados[$index]">
{{ campo.nome }}
</label>
<pre>{{ campos_selecionados | json }}</pre>
</div>
In the example above,% w_of%, even when the checkbox is not selected, is marked as Array
.
How can I make my checkbox generate a null
with the items that were selected?