Comunicación con backend. Permite cargar un usuario de la BD

This commit is contained in:
onsaliyo 2021-03-16 10:23:46 +01:00
parent f1bf8ff75e
commit 36426bc643
3 changed files with 12 additions and 9 deletions

View File

@ -21,9 +21,11 @@ export class ApiService {
validateUser(user: UserLogin): Observable<User>{
return this.http.post<User>("http://localhost:3307/api/consultas/users", user);
return this.http.post<User>("http://localhost:3307/api/consultas/users", user)
}
}

View File

@ -1,5 +1,6 @@
import { Injectable } from '@angular/core';
import { Router } from '@angular/router';
import { VirtualTimeScheduler } from 'rxjs';
import { ApiService } from './api.service';
import { User } from './user';
import { UserLogin } from './user-login';
@ -21,7 +22,7 @@ export class LoginService {
};
}
validateUser(login: string, password: string): User {
validateUser(login: string, password: string): void{
let userlogin: UserLogin = {
loginUser: login,
@ -29,12 +30,12 @@ export class LoginService {
}
this.apiService.validateUser(userlogin)
.subscribe(user => this.user = user)
return this.user;
.subscribe(user => {
this.user = user;
console.log(this.user);
})
}
}

View File

@ -20,12 +20,12 @@ export class LoginPage implements OnInit {
this.user = this.loginService.user;
}
async login() {
login() {
this.username = (<HTMLInputElement>document.getElementById("username")).value;
this.password = (<HTMLInputElement>document.getElementById("password")).value;
this.user = await this.loginService.validateUser(this.username, this.password);
console.log(this.user.username);
this.loginService.validateUser(this.username, this.password)
}