An array was created and initialized with various fields, including targaauto. Within the add function, there is a check for an error alert if the length of the car plate is equal to 0. However, this functionality does not work correctly as the alert does not show up when the license plate is not entered. Various conditions were tried within the if statement in addition to the one defined in the code.
PROVEN CONDITIONS
if (cars.targaauto.length == 0)
if ($ cars.targaauto.length == 0)
if (targaauto.length == 0)
START ANGULAR JS CODE
angular.module('tabelle', [])
.controller('test', function($scope){
$scope.cars = [{id: "1", targaauto : "AR152FP", datiintestatario : "Maurizio Generosi",
marca :
"FIAT PUNTO", id_bottone: "1"},
{id: "2", targaauto : "AR34512", datiintestatario : "Nicola Lops", marca :
"TOYOTA YARIS", id_bottone: "2"},
{id: "3", targaauto : "BS25671", datiintestatario : "Sabrina
De Martino",
marca
: "FIAT PANDA", id_bottone: "3"}];
$scope.aggiungi = function() {
if($scope.cars.targaauto.length==0){
alert("Errore! Inserire la targa");
}
$scope.cars.push({
id: $scope.id,
targaauto: $scope.targaauto,
datiintestatario: $scope.datiintestatario,
marca: $scope.marca,
id_bottone: $scope.id_bottone
})
$scope.id = " ";
$scope.targaauto = " ";
$scope.datiintestatario = " ";
$scope.marca = " ";
};
$scope.rigadaeliminare = function(indice) {
$scope.idcancellare = indice;
};
$scope.rimuovi = function () {
$scope.cars.splice($scope.idcancellare, 1);
};
//SELEZIONE INDICE DELLA RIGA DEL RECORD
function rigadamodificare(indice){
for(let i=0; i<$scope.cars.length;i++){
if($scope.cars[i].id==indice){
return i;
}
}
return -1;
};
$scope.aggiorna = function(id) {
let index = rigadamodificare(id);
let i = $scope.cars[index];
$scope.id=i.id;
$scope.targaauto=i.targaauto;
$scope.datiintestatario=i.datiintestatario;
$scope.marca=i.marca;
};
$scope.salva = function() {
let index = rigadamodificare($scope.id);
$scope.cars[index].targaauto = $scope.targaauto;
$scope.cars[index].datiintestatario = $scope.datiintestatario;
$scope.cars[index].marca = $scope.marca;
$scope.id = " ";
$scope.targaauto = " ";
$scope.datiintestatario = " ";
$scope.marca = " ";
};
});