Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import { Injectable } from '@angular/core';
- import { HttpClient, HttpHeaders , HttpParams } from '@angular/common/http';
- import { User } from '../models/user';
- import { tap, map, shareReplay, share, publishReplay, refCount } from 'rxjs/operators';
- import { Observable } from 'rxjs';
- @Injectable({ providedIn: 'root' })
- export class UserService {
- headers = new HttpHeaders({
- 'Content-Type': 'application/json',
- 'Authorization': 'application/json'
- });
- host = 'http://localhost:8080/';
- public user:Observable<User>;
- constructor(private http: HttpClient) { }
- getUserById(userId:number){
- let params = new HttpParams().set('userId', String(userId));
- let options = { headers: this.headers, params: params };
- return this.http.get(this.host + 'getUserById', options)
- .pipe(
- map( response => response as User ),
- tap( user => console.table(user) )
- );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement