I am trying to get the status from an API.
As you can see in the image it returns the 423 status, I want to make validations of this form using the status, if status is different from 200 (which mean everything is ok) show the error on the array, if not then pass to the dashboard.
There is my code from login.component.ts, can you help me with the status and maybe a little with the logic of the sentences to make the validations?
import { Component, OnInit } from '@angular/core';
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
import { LoginService } from './login.service';
import { LoginInt } from 'src/app/Interfaces/login.interfaces';
import { ResponseLInt } from 'src/app/Interfaces/responseL.interface';
@Component({
selector: 'app-login',
templateUrl: './login.component.html',
styleUrls: ['./login.component.css']
})
export class LoginComponent implements OnInit {
FLogin: FormGroup = this.fb.group({
email: ['', [Validators.required, Validators.email]],
password: ['', [Validators.required, Validators.minLength(5)]]
}
)
constructor(private fb: FormBuilder, private api:LoginService) { }
campoValido (campo: string){
return this.FLogin.controls[campo].errors && this.FLogin.controls[campo].touched
}
guardar(form:LoginInt){
this.api.LoginPass(form).subscribe(data =>{
console.log(data);
;}
},
)
ngOnInit(): void {
}
}
This is my login service
import { Injectable } from "@angular/core";
import { LoginInt } from '../../../Interfaces/login.interfaces';
import { ResponseLInt } from '../../../Interfaces/responseL.interface';
import { HttpClient, HttpHeaders } from '@angular/common/http';
import { Observable } from "rxjs";
@Injectable({
providedIn: 'root'
})
export class LoginService{
url: string='https://apitest.e-bango.com';
constructor(private http:HttpClient){}
LoginPass(form:LoginInt):Observable<ResponseLInt>{
let direccion = this.url + "/api/auth/login"
return this.http.post<ResponseLInt>(direccion,form)
}
}