Skip to content

Instantly share code, notes, and snippets.

@nicowernli
Created August 31, 2018 07:43
Show Gist options
  • Save nicowernli/7f03e891cb5bfa5c0eabe76ffb133980 to your computer and use it in GitHub Desktop.
Save nicowernli/7f03e891cb5bfa5c0eabe76ffb133980 to your computer and use it in GitHub Desktop.
Planet service
import { Injectable } from '@angular/core';
import { HttpClient, HttpParams } from '@angular/common/http';
import { Observable } from 'rxjs';
import { map } from 'rxjs/operators';
import { Planet } from './planet';
@Injectable()
export class PlanetService {
constructor(private http: HttpClient) {}
search(term: string): Observable<Planet[]> {
const params = new HttpParams()
.set('search', term);
return this.http.get<any>('https://swapi.co/api/planets', { params })
.pipe(map<any, Planet[]>(result => result.results));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment