andreadc

user.service.ts

Mar 4th, 2020
298
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import { Injectable } from '@angular/core';
  2. import { HttpClient, HttpHeaders , HttpParams } from '@angular/common/http';
  3.  
  4. import { User } from '../models/user';
  5. import { tap, map, shareReplay, share, publishReplay, refCount } from 'rxjs/operators';
  6. import { Observable } from 'rxjs';
  7.  
  8. @Injectable({ providedIn: 'root' })
  9. export class UserService {
  10.    
  11.     headers = new HttpHeaders({
  12.         'Content-Type':  'application/json',
  13.         'Authorization': 'application/json'
  14.     });
  15.      
  16.     host = 'http://localhost:8080/';
  17.  
  18.     constructor(private http: HttpClient) { }
  19.  
  20.     getUserById(userId:number){
  21.        
  22.         let params = new HttpParams().set( 'userId', String(userId) );
  23.         let options = { headers: this.headers, params: params };
  24.  
  25.         return this.http.get(this.host + 'getUserById', options)
  26.             .pipe(
  27.                 map((user:User) => {
  28.                     return user
  29.                 })
  30.             )
  31.     }
  32.  
  33. }
Advertisement
Add Comment
Please, Sign In to add comment