Add search to the dashboard
This commit is contained in:
parent
5f12d19dbc
commit
64c40998b9
|
@ -5,3 +5,5 @@
|
||||||
{{hero.name}}
|
{{hero.name}}
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<app-hero-search></app-hero-search>
|
|
@ -65,6 +65,21 @@ export class HeroService {
|
||||||
catchError(this.handleError<Hero>('deleteHero'))
|
catchError(this.handleError<Hero>('deleteHero'))
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* GET heroes whose name contains search term */
|
||||||
|
searchHeroes(term: string): Observable<Hero[]> {
|
||||||
|
if (!term.trim()) {
|
||||||
|
// if not search term, return empty hero array.
|
||||||
|
return of([]);
|
||||||
|
}
|
||||||
|
return this.http.get<Hero[]>(`${this.heroesUrl}/?name=${term}`)
|
||||||
|
.pipe(
|
||||||
|
tap(x => x.length ?
|
||||||
|
this.log(`found heroes matching "${term}"`) :
|
||||||
|
this.log(`no heroes matching "${term}"`)),
|
||||||
|
catchError(this.handleError<Hero[]>('searchHeroes', []))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handle Http operation that failed.
|
* Handle Http operation that failed.
|
||||||
|
|
Loading…
Reference in New Issue