This repository was archived by the owner on Dec 4, 2017. It is now read-only.
File tree 4 files changed +205
-108
lines changed
4 files changed +205
-108
lines changed Original file line number Diff line number Diff line change @@ -11,7 +11,7 @@ import { LoadingComponent } from './loading.component';
11
11
import { HeroSearchComponent } from './hero-search.component' ;
12
12
import { HeroDetailComponent } from './hero-detail.component' ;
13
13
import { HeroListComponent } from './hero-list.component' ;
14
-
14
+ import { HeroCounterComponent } from './hero-counter.component' ;
15
15
import { LoadingService } from './loading.service' ;
16
16
import { HeroService } from './hero.service' ;
17
17
@@ -34,7 +34,8 @@ import { ApiErrorHandlerService } from './api-error-handler.service';
34
34
LoadingComponent ,
35
35
HeroSearchComponent ,
36
36
HeroDetailComponent ,
37
- HeroListComponent
37
+ HeroListComponent ,
38
+ HeroCounterComponent
38
39
] ,
39
40
providers : [
40
41
HeroService ,
Original file line number Diff line number Diff line change
1
+ // // #docplaster
2
+ // // #docregion
3
+ // import { Component, OnInit } from '@angular/core';
4
+ //
5
+ // import { HeroService } from './hero.service';
6
+ // import { Hero } from './hero';
7
+ //
8
+ // @Component ({
9
+ // template: `
10
+ // <h2>HEROES</h2>
11
+ // <ul class="items">
12
+ // <li *ngFor="let hero of heroes">
13
+ // <span class="badge">{{ hero.id }}</span> {{ hero.name }}
14
+ // </li>
15
+ // </ul>
16
+ // `
17
+ // })
18
+ // export class HeroListComponent implements OnInit {
19
+ // heroes: Hero[];
20
+ //
21
+ // constructor(
22
+ // private service: HeroService
23
+ // ) {}
24
+ //
25
+ // ngOnInit() {
26
+ // this.service.getHeroes()
27
+ // .subscribe(heroes => this.heroes = heroes);
28
+ // }
29
+ // }
30
+ // // #enddocregion
Original file line number Diff line number Diff line change
1
+ // #docplaster
2
+ // #docregion
3
+ import { Component , OnInit } from '@angular/core' ;
4
+ import { Subject } from 'rxjs/Subject' ;
5
+ import { Observable } from 'rxjs/Observable' ;
6
+ import { Observer } from 'rxjs/Observer' ;
7
+ import { Subscription } from 'rxjs/Subscription' ;
8
+
9
+ import { HeroService } from './hero.service' ;
10
+ import { Hero } from './hero' ;
11
+
12
+ @Component ( {
13
+ selector : 'hero-counter' ,
14
+ template : `
15
+ <h2>HERO COUNTER</h2>
16
+ <p>
17
+ Heroes {{ count }}
18
+ </p>
19
+ `
20
+ } )
21
+ export class HeroCounterComponent implements OnInit {
22
+ count : number = 0 ;
23
+ counter$ : Observable < number > ;
24
+ sub : Subscription ;
25
+ destroy$ = new Subject ( ) ;
26
+
27
+ ngOnInit ( ) {
28
+ this . counter$ = Observable . create ( ( observer : Observer < number > ) => {
29
+ const interval = setInterval ( ( ) => {
30
+ observer . next ( this . count ++ ) ;
31
+ } , 1000 ) ;
32
+ } ) ;
33
+
34
+ this . counter$
35
+ . takeUntil ( this . destroy$ )
36
+ . subscribe ( ) ;
37
+ }
38
+
39
+ ngOnDestroy ( ) {
40
+ this . destroy$ . next ( ) ;
41
+ }
42
+ }
43
+ // #enddocregion
You can’t perform that action at this time.
0 commit comments