display results

master
Matt Huntington 9 years ago
parent 78f460ea07
commit ba47925d4b

@ -3,3 +3,9 @@
<input [(ngModel)]="name" type="text" placeholder="Character Name"/> <input [(ngModel)]="name" type="text" placeholder="Character Name"/>
<input (click)="findCharacter(name)" type="submit" value="Search"/> <input (click)="findCharacter(name)" type="submit" value="Search"/>
</section> </section>
<section *ngIf="results">
<h2>Search Results</h2>
<ul>
<li *ngFor="let character of results">{{character.name}}</li>
</ul>
</section>

@ -8,6 +8,7 @@ import 'rxjs/add/operator/toPromise';
styleUrls: ['./search.component.css'] styleUrls: ['./search.component.css']
}) })
export class SearchComponent implements OnInit { export class SearchComponent implements OnInit {
results;
constructor( constructor(
private http: Http private http: Http
@ -16,7 +17,7 @@ export class SearchComponent implements OnInit {
findCharacter(name){ findCharacter(name){
this.http.get('http://swapi.co/api/people/?search=' + name) this.http.get('http://swapi.co/api/people/?search=' + name)
.toPromise() .toPromise()
.then(response => console.log(response.json())); .then(response => this.results = response.json().results );
} }
ngOnInit() { ngOnInit() {

Loading…
Cancel
Save