|
1 | 1 | /* tslint:disable: member-ordering forin */
|
2 | 2 | // #docplaster
|
3 | 3 | // #docregion
|
4 |
| -import { Component, OnInit } from '@angular/core'; |
5 |
| -import { Observable } from 'rxjs/Observable'; |
| 4 | +import { Component, OnInit } from '@angular/core'; |
| 5 | + |
| 6 | +// #docregion rxjs-imports |
| 7 | +import { Observable } from 'rxjs/Observable'; |
| 8 | +import 'rxjs/add/operator/debounceTime'; |
| 9 | +import 'rxjs/add/operator/distinctUntilChanged'; |
| 10 | +import 'rxjs/add/operator/switchMap'; |
| 11 | + |
6 | 12 | // #docregion import-subject
|
7 |
| -import { Subject } from 'rxjs/Subject'; |
| 13 | +import { Subject } from 'rxjs/Subject'; |
8 | 14 | // #enddocregion import-subject
|
9 | 15 |
|
10 | 16 | import { WikipediaService } from './wikipedia.service';
|
11 | 17 |
|
12 | 18 | @Component({
|
13 | 19 | moduleId: module.id,
|
14 | 20 | selector: 'my-wiki-smart',
|
15 |
| - templateUrl: './wiki.component.html', |
| 21 | + template: ` |
| 22 | + <h1>Smarter Wikipedia Demo</h1> |
| 23 | + <p>Search when typing stops</p> |
| 24 | + <input #term (keyup)="search(term.value)"/> |
| 25 | + <ul> |
| 26 | + <li *ngFor="let item of items | async">{{item}}</li> |
| 27 | + </ul>`, |
16 | 28 | providers: [ WikipediaService ]
|
17 | 29 | })
|
18 | 30 | export class WikiSmartComponent implements OnInit {
|
19 |
| - title = 'Smarter Wikipedia Demo'; |
20 |
| - fetches = 'Fetches when typing stops'; |
21 | 31 | items: Observable<string[]>;
|
22 | 32 |
|
| 33 | + constructor (private wikipediaService: WikipediaService) {} |
| 34 | + |
23 | 35 | // #docregion subject
|
24 | 36 | private searchTermStream = new Subject<string>();
|
25 | 37 | search(term: string) { this.searchTermStream.next(term); }
|
26 | 38 | // #enddocregion subject
|
27 | 39 |
|
28 |
| - constructor (private wikipediaService: WikipediaService) {} |
29 |
| - |
30 | 40 | ngOnInit() {
|
31 | 41 | // #docregion observable-operators
|
32 | 42 | this.items = this.searchTermStream
|
|
0 commit comments