Matt Huntington 9 years ago
parent 7ec27de8c8
commit 032595bb65

@ -1,5 +1,6 @@
import { Component, OnInit } from '@angular/core'; import { Component, OnInit } from '@angular/core';
import { Http } from '@angular/http'; import { Http } from '@angular/http';
import 'rxjs/add/operator/map';
import 'rxjs/add/operator/toPromise'; import 'rxjs/add/operator/toPromise';
@Component({ @Component({
@ -15,9 +16,16 @@ export class SearchComponent implements OnInit {
) { } ) { }
findCharacter(name){ findCharacter(name){
this.http.get('http://swapi.co/api/people/?search=' + name) const result = this.http.get('http://swapi.co/api/people/?search=' + name)
.toPromise() .map((response)=>{
.then(response => console.log(this.results = response.json().results) ); return response.json().results;
}).subscribe(
(response)=>{
this.results = response;
}
);
// .toPromise()
// .then(response => console.log(this.results = response.json().results) );
} }
ngOnInit() { ngOnInit() {

Loading…
Cancel
Save