I created this auth-api.ts service, having a login method:
login(username, password)
{
let headerOptions = new HttpHeaders();
headerOptions.append('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8');
const httpParams = new HttpParams()
.set('username', username)
.set('password', password);
return this.http.post('http://dev.local/scripts/login.php', httpParams, {
headers: headerOptions
}).pipe(map(
res=>{
console.log('user '+res)
},
err=>
console.log(err)
))
}
On button click, this method will be called inside login.component.ts using this method:
login(){
const user = this.loginGroup.get('username').value;
const pass = this.loginGroup.get('password').value;
this.auth.login(user, pass).subscribe(
(data)=>{
console.log(data);
this.loginGroup.reset();
},
(error)=>{
console.log(error)
}
)
}
The problem is that the console.log(res) from the api login method is returning the value, but the `console.log(data) from the second login method is returning undefined.
What I want is to make some conditions on data, so that's why I can't.
