master
Matt Huntington 9 years ago
parent 5d4a97221d
commit ba1e64b107

@ -3,23 +3,23 @@ import { Http } from '@angular/http';
import 'rxjs/add/operator/toPromise'; import 'rxjs/add/operator/toPromise';
@Component({ @Component({
selector: 'app-search', selector: 'app-search',
templateUrl: './search.component.html', templateUrl: './search.component.html',
styleUrls: ['./search.component.css'] styleUrls: ['./search.component.css']
}) })
export class SearchComponent implements OnInit { export class SearchComponent implements OnInit {
constructor( constructor(
private http: Http private http: Http
) { } ) { }
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 => console.log(response.json()));
} }
ngOnInit() { ngOnInit() {
} }
} }

@ -11,6 +11,8 @@
1. Set a component property to the value of an input 1. Set a component property to the value of an input
1. Invoke a function when the user clicks a button 1. Invoke a function when the user clicks a button
1. Add the ability to make AJAX requests 1. Add the ability to make AJAX requests
1. Make an AJAX request
1. Display AJAX results in app
## Create a new app ## Create a new app
@ -172,3 +174,5 @@ findCharacter(name){
The `rxjs/add/operator/toPromise` import that we previously wrote adds the ability to change the `Observable` (more on this in another lecture) into a `Promise` The `rxjs/add/operator/toPromise` import that we previously wrote adds the ability to change the `Observable` (more on this in another lecture) into a `Promise`
You can test this by looking in the console You can test this by looking in the console
## Display AJAX results in app

Loading…
Cancel
Save