1
Good evening, guys, I’m a beginner in the development of apps using Angular, and currently, I came across the following situation: I need to register a certain driver, the same has categories on CNH, I then decided to do a checkbox with the values (A,B,C,D). However, whether I select the checkbox or not, it goes as true to my service (REST using jersey). In my Insert method, I declare the checkbox array and already set true values to default, I think I’m missing this point. How do I declare a chckbox array belonging to my driver object outside of this function? Dese already thank you!
my view:
<div ng-app="Motorista" ng-controller="motoristaController as vm">
<fieldset>
<legend> Categoria CNH </legend>
<input type="checkbox" ng-model="vm.motorista.categoria_cnh.value1" />A
</br>
<input type="checkbox" ng-model="vm.motorista.categoria_cnh.value2" />B
</br>
<input type="checkbox" ng-model="vm.motorista.categoria_cnh.value3" />C
</br>
<input type="checkbox" ng-model="vm.motorista.categoria_cnh.value4" />D
</br>
<input type="checkbox" ng-model="vm.motorista.categoria_cnh.value5" />E
</br>
</fieldset>
<input type="button" ng-click="vm.inserir()" value="Inserir"/>
</div>
my controller:
var linkservice = "http://localhost:8080/Cast_Frotas/rest/motorista/";
var app = angular.module('Motorista',[]);
app.controller('motoristaController', function ($scope, $http) {
//vm.inserir = inserir;
iniciar();
function iniciar() {
this.motorista = {};
this.motorista.categoria_cnh = {
value1 : true,
value2 : true,
value3 : true,
value4 : true,
value5 : true
};
}
//PEGANDO ITENS DA SESSION STORAGE
/*var motorista = window.localStorage.getItem('motorista');
$scope.motorista = JSON.parse(motorista);*/
$http.get(linkservice + "select").then(function (response) {
$scope.registros = response.data;
});
$http.get(linkservice + "selectPrestador").then(function (response) {
$scope.prestadores = response.data;
});
$http.get(linkservice + "selectCurso").then(function (response) {
$scope.cursos = response.data;
});
$scope.inserir = function (){
alert(this.motorista.categoria_cnh);
$scope.jsonObj = angular.toJson($scope.motorista, false);
}
});
All the way back to save?
– Sorack
then, I send the object (Json) to my service, that was the pattern they determined in the project, @sorack
– Matheus Minguini
But the checkbox will always be true, I can’t move right with Angular :(
– Matheus Minguini
I’ve seen what your problem was. You want some tips to improve it there too or just the solution?
– Sorack
@Sorack, if you could send me both, I’d be most grateful
– Matheus Minguini
On the improvement part, could you explain to me?
– Matheus Minguini