Hola estoy haciendo un login y para ello estoy siguiendo un tutorial, pero al a hora de ir a mi componente /login me dice en la consola del navegador
ERROR Error: "[object Object]"
Sin embargo en la terminal no me tira ningún error, el componente del login es el siguiente:
import { Component, OnInit } from '@angular/core';
import { LoginService } from '../../services/login.service';
import { Router } from '@angular/router';
export class LoginComponent implements OnInit {
constructor(
private loginService: LoginService,
private router: Router
) { }
ngOnInit() {
this.loginService.login('peter@klaven', 'cityslicka').subscribe(
res => {
console.log(res);
});
}
logIn(username: string, password: string, event: Event) {
event.preventDefault(); // Avoid default action for the submit button of the login form
// Calls service to login user to the api rest
this.loginService.login(username, password).subscribe(
res => {
console.log(res);
},
error => {
console.error(error);
},
() => this.navigate()
);
}
navigate() {
this.router.navigateByUrl('/home');
}
}
El @Component lo he omitido ya que es lógico, también he creado un servicio que se llama login.service.ts y un login.component.html para hacer el furmulario de inicio de sesión ya ahí me he quedado por que me tiraba el error.
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Observable } from 'rxjs/';
@Injectable()
export class LoginService {
constructor(private http: HttpClient) {
}
login(username:string, password:string) {
return this.http.post('https://reqres.in/api/login', {
email: username,
password: password,
});
}
}
El tutorial que estoy siguiendo es el siguiente: https://codingpotions.com/angular-login-sesion/
console.error(error)
porconsole.error(JSON.stringify(error))
– Pablo Lozano el 4 jul. 19 a las 9:12