Advertisement
Guest User

Untitled

a guest
Nov 22nd, 2019
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.69 KB | None | 0 0
  1. import { Injectable } from '@angular/core';
  2. import { HttpClient } from '@angular/common/http';
  3. import { Observable } from 'rxjs';
  4. import { map } from 'rxjs/operators';
  5.  
  6.  
  7. export enum SearchType{
  8.  
  9. all='',
  10. movie='movie',
  11. series='series',
  12. episodes='episodes'
  13.  
  14. };
  15.  
  16. @Injectable({
  17. providedIn: 'root'
  18. })
  19.  
  20. export class ApiService {
  21.  
  22.  
  23.  
  24. url = 'http://www.omdbapi.com/';
  25. apiKey = '258f0ace';
  26.  
  27. constructor(private http: HttpClient) { }
  28.  
  29.  
  30. searchData(title: string, type: SearchType): Observable<any> {
  31. return this.http.get(`${this.url}?s=${encodeURI(title)}&type=${type}&apikey=${this.apiKey}`).pipe(
  32. map(results => results['Search'])
  33. );
  34. }
  35.  
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement