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