master
Matt Huntington 9 years ago
parent a85e065958
commit 977b50ee93

@ -5,7 +5,7 @@
<section *ngIf="results"> <section *ngIf="results">
<h2>Search Results</h2> <h2>Search Results</h2>
<ul> <ul>
<li *ngFor="let character of results | async"> <li *ngFor="let character of results">
<h3>{{character.name}}</h3> <h3>{{character.name}}</h3>
<dl> <dl>
<dt>Birth Year</dt> <dt>Birth Year</dt>

@ -27,10 +27,14 @@ export class SearchComponent implements OnInit {
} }
ngOnInit() { ngOnInit() {
this.results = this.searchTerms this.searchTerms
.debounceTime(300) .debounceTime(300)
.distinctUntilChanged() .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){ createAPIObservable(name){
return this.http return this.http
.get('http://swapi.co/api/people/?search=' + name) .get('http://swapi.co/api/people/?search=' + name);
.map(response=> response.json().results );
} }
} }

Loading…
Cancel
Save