Trotyl Yu accd74c0a2 docs(server-communication): Fix typo in example (#2199)
* docs(server-communication): Fix typo in example

Clearly we're transforming the response, not the request.

* docs(server-communication): Fix typo in example

Clearly we're transforming the response, not the request.
2016-08-26 10:12:37 -07:00

29 lines
813 B
TypeScript

// #docregion
import { Injectable } from '@angular/core';
import { Jsonp, URLSearchParams } from '@angular/http';
@Injectable()
export class WikipediaService {
constructor(private jsonp: Jsonp) {}
search (term: string) {
let wikiUrl = 'http://en.wikipedia.org/w/api.php';
// #docregion search-parameters
let params = new URLSearchParams();
params.set('search', term); // the user's search value
params.set('action', 'opensearch');
params.set('format', 'json');
params.set('callback', 'JSONP_CALLBACK');
// #enddocregion search-parameters
// #docregion call-jsonp
// TODO: Add error handling
return this.jsonp
.get(wikiUrl, { search: params })
.map(response => <string[]> response.json()[1]);
// #enddocregion call-jsonp
}
}