2016-05-23 22:24:15 -04:00
|
|
|
// #docregion
|
|
|
|
import { Injectable } from '@angular/core';
|
|
|
|
import { Http, Response } from '@angular/http';
|
2016-07-27 09:00:59 -04:00
|
|
|
import { Observable } from 'rxjs';
|
2016-05-23 22:24:15 -04:00
|
|
|
|
|
|
|
import { Hero } from './hero';
|
|
|
|
|
|
|
|
@Injectable()
|
|
|
|
export class HeroSearchService {
|
|
|
|
|
|
|
|
constructor(private http: Http) {}
|
|
|
|
|
2016-07-27 09:00:59 -04:00
|
|
|
search(term: string): Observable<Hero[]> {
|
2016-05-23 22:24:15 -04:00
|
|
|
return this.http
|
2016-09-14 10:37:28 -04:00
|
|
|
.get(`app/heroes/?name=${term}`)
|
2016-05-23 22:24:15 -04:00
|
|
|
.map((r: Response) => r.json().data as Hero[]);
|
|
|
|
}
|
|
|
|
}
|