File tree Expand file tree Collapse file tree 1 file changed +17
-4
lines changed
Expand file tree Collapse file tree 1 file changed +17
-4
lines changed Original file line number Diff line number Diff line change @@ -13,16 +13,29 @@ import {HelloService} from './hello.service';
1313} )
1414export class HelloComponent {
1515
16+ // vars
1617 private jsonResponse : string ;
1718 private message : string ;
19+ private subscription ;
1820
21+ // constructor
1922 constructor ( private helloService : HelloService ) { }
2023
24+ // on-init
2125 ngOnInit ( ) {
22- this . helloService . getTest ( ) . subscribe (
23- data => { this . jsonResponse = JSON . stringify ( data ) ,
24- this . message = data . test . message } ,
25- ( ) => console . log ( '../test/get/json returned: \n' + this . jsonResponse )
26+ // save subscription
27+ this . subscription = this . helloService . getTest ( )
28+ . subscribe (
29+ ( data ) => { this . jsonResponse = JSON . stringify ( data ) ;
30+ this . message = data . test . message ; } ,
31+ ( err ) => console . log ( err ) ,
32+ ( ) => console . log ( 'hello service test complete' )
2633 ) ;
2734 }
35+
36+ // on-destroy
37+ ngOnDestroy ( ) {
38+ // unsubscribe
39+ this . subscription . unsubscribe ( ) ;
40+ }
2841}
You can’t perform that action at this time.
0 commit comments