@ -5,7 +5,7 @@
<section *ngIf="results">
<h2>Search Results</h2>
<ul>
<li *ngFor="let character of results | async">
<li *ngFor="let character of results">
<h3>{{character.name}}</h3>
<dl>
<dt>Birth Year</dt>
@ -27,10 +27,14 @@ export class SearchComponent implements OnInit {
}
ngOnInit() {
this.results = this.searchTerms
this.searchTerms
.debounceTime(300)
.distinctUntilChanged()
.switchMap(name => this.characterSearchService.createAPIObservable(name));
.subscribe(name => {
this.characterSearchService.createAPIObservable(name).subscribe(results => {
this.results = results.json().results;
})
@ -9,7 +9,6 @@ export class SearchService {
createAPIObservable(name){
return this.http
.get('http://swapi.co/api/people/?search=' + name)
.get('http://swapi.co/api/people/?search=' + name);
.map(response=> response.json().results );