2015-12-01 12:15:14 +01:00
|
|
|
// #docregion
|
2016-05-03 14:06:32 +02:00
|
|
|
import { Component } from '@angular/core';
|
|
|
|
import { Observable } from 'rxjs/Observable';
|
2016-02-02 11:22:48 -08:00
|
|
|
|
2016-05-03 14:06:32 +02:00
|
|
|
import { WikipediaService } from './wikipedia.service';
|
2015-12-01 12:15:14 +01:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'my-wiki',
|
2017-01-05 01:12:06 -08:00
|
|
|
template: `
|
|
|
|
<h1>Wikipedia Demo</h1>
|
|
|
|
<p>Search after each keystroke</p>
|
|
|
|
<input #term (keyup)="search(term.value)"/>
|
|
|
|
<ul>
|
|
|
|
<li *ngFor="let item of items | async">{{item}}</li>
|
|
|
|
</ul>`,
|
2016-10-19 23:17:50 -07:00
|
|
|
providers: [ WikipediaService ]
|
2015-12-01 12:15:14 +01:00
|
|
|
})
|
|
|
|
export class WikiComponent {
|
2016-06-08 01:06:25 +02:00
|
|
|
items: Observable<string[]>;
|
2015-12-01 12:15:14 +01:00
|
|
|
|
2017-01-05 01:12:06 -08:00
|
|
|
constructor (private wikipediaService: WikipediaService) { }
|
|
|
|
|
2015-12-01 12:15:14 +01:00
|
|
|
search (term: string) {
|
2016-05-03 14:06:32 +02:00
|
|
|
this.items = this.wikipediaService.search(term);
|
2015-12-01 12:15:14 +01:00
|
|
|
}
|
|
|
|
}
|