I'm trying to make a simple login using information taken from a database in the form of json .
I took that information using http.get and save it in a variable called this.info .
So what I want to do is the following:
json (in this case this.info ) and save them in a variable. [(ngModel)] and if it is true that it shows a alert . I've already tried using for , foreach , map . And at the time of making the comparison marks as false.
Here is the code you used as mentioned above.
map
us: any;
cn: any;'
this.us = this.info.map(({ username }) => username);
this.cn = this.info.map(({ contrasena }) => contrasena);
for
us = [];
cn = [];
for (let x of this.info) {
this.us.push(x.username);
this.cn.push(x.password);
}
forEach
this.info.forEach(function(x) {
this.us.push(x.usuario);
this.cn.push(x.contrasena);
});
But it goes wrong when doing the following:
// this.usern y this.passw vienen del [(ngModel)]
if (this.usern == this.us) {
if(this.passw == this.cn) {
alert('Datos Correctos');
}
} else {
alert('Datos Incorrectos');
}