2015-12-01 12:15:14 +01:00
|
|
|
// #docregion
|
2016-04-27 11:28:22 -07:00
|
|
|
import {Component} from '@angular/core';
|
|
|
|
import {JSONP_PROVIDERS} from '@angular/http';
|
2015-12-01 12:15:14 +01:00
|
|
|
import {Observable} from 'rxjs/Observable';
|
2016-02-02 11:22:48 -08:00
|
|
|
|
2015-12-01 12:15:14 +01:00
|
|
|
import {WikipediaService} from './wikipedia.service';
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'my-wiki',
|
|
|
|
template: `
|
|
|
|
<h1>Wikipedia Demo</h1>
|
|
|
|
<p><i>Fetches after each keystroke</i></p>
|
2016-02-02 02:27:52 -08:00
|
|
|
|
2015-12-01 12:15:14 +01:00
|
|
|
<input #term (keyup)="search(term.value)"/>
|
2016-02-02 02:27:52 -08:00
|
|
|
|
2015-12-01 12:15:14 +01:00
|
|
|
<ul>
|
2016-04-29 01:36:35 +01:00
|
|
|
<li *ngFor="let item of items | async">{{item}}</li>
|
2015-12-01 12:15:14 +01:00
|
|
|
</ul>
|
|
|
|
`,
|
|
|
|
providers:[JSONP_PROVIDERS, WikipediaService]
|
|
|
|
})
|
|
|
|
export class WikiComponent {
|
|
|
|
|
|
|
|
constructor (private _wikipediaService: WikipediaService) {}
|
|
|
|
|
2016-02-02 02:27:52 -08:00
|
|
|
items: Observable<string[]>;
|
2015-12-01 12:15:14 +01:00
|
|
|
|
|
|
|
search (term: string) {
|
|
|
|
this.items = this._wikipediaService.search(term);
|
|
|
|
}
|
|
|
|
}
|