2016-02-02 02:27:52 -08:00

25 lines
632 B
TypeScript

// Create the query string by hand
// #docregion
import {Injectable} from 'angular2/core';
import {Jsonp} from 'angular2/http';
@Injectable()
export class WikipediaService {
constructor(private jsonp: Jsonp) { }
// TODO: Add error handling
search(term: string) {
let wikiUrl = 'http://en.wikipedia.org/w/api.php';
// #docregion query-string
let queryString =
`?search=${term}&action=opensearch&format=json&callback=JSONP_CALLBACK`
return this.jsonp
.get(wikiUrl + queryString)
.map(request => <string[]> request.json()[1]);
// #enddocregion query-string
}
}