Friday, 10 January 2020

Angular Http service example




thi@Injectable({
  providedIn: 'root'
})

export class LoginHttpService {
  constructor(private http: HttpClient) { }
  callLoginApi(loginReqParam: any): Observable<any> {
    const url = environment.LOGIN_URL;              
    let reqBody = JSON.stringify(loginReqParam);
    return this.http.post(url + '/login', reqBody )
    .pipe(
      map(b => <any>{
         status: b.status,
         token: b.token,
         message: b.token
      }),
       tap(lastResponse => console.log(lastResponse))
     );
  }

}

Share: