I have a object “Trucks” and I trying to do a simple validation and nothing
I would like to do the following
if(password == ‘…’ && placa == ‘…’)
alert(login ok)
navctrl.setRoot(‘somepage’)
else if (password != ‘…’)
alert(‘error, password is wrong’)
else if (placa!= ‘…’)
alert(‘error, placais wrong’)
Im my login.ts I have the following code I don’t know if it’s right fist I get all trucks in list ok
getTrucks() {
this.truckService.getTrucks()
.subscribe(
result => this.trucks = result
)
}
and the second on bellow I filter the trucks
filterTruck() {
return this.trucks.filter((item) => {
if(item.placa == this.truck.placa && item.password == this.truck.password) {
// this.navCtrl.setRoot('TabsPage');
// this.auth.authentication(true);
// this.auth.truckLogedd(user);
// return true;
console.log(item)
} else if(item.placa != this.truck.placa) {
return false;
}
return false;
})
}
I’ve trying to use for but I did not make it
filterTruck(users) {
for(let user of users) {
if(user.password != this.truck.password || user.placa != this.truck.placa) {
this.showAlert('Ops!', 'Senha ou placa errada!')
break;
} else {
this.navCtrl.setRoot('TabsPage');
this.auth.authentication(true);
this.auth.truckLogedd(user);
break;
}
}
}