File tree Expand file tree Collapse file tree 2 files changed +15
-6
lines changed Expand file tree Collapse file tree 2 files changed +15
-6
lines changed Original file line number Diff line number Diff line change @@ -39,4 +39,7 @@ typings
3939
4040# Generated files
4141app /** /* .js
42- app /** /* .js.map
42+ app /** /* .js.map
43+
44+ # VS Code settings
45+ .vscode
Original file line number Diff line number Diff line change 1- import { Component , OnInit } from '@angular/core' ;
1+ import { Component , OnDestroy } from '@angular/core' ;
2+ import { Subscription } from 'rxjs/Subscription' ;
23
34import { AlertService } from '../_services/index' ;
45
@@ -8,12 +9,17 @@ import { AlertService } from '../_services/index';
89 templateUrl : 'alert.component.html'
910} )
1011
11- export class AlertComponent {
12+ export class AlertComponent implements OnDestroy {
13+ private subscription : Subscription ;
1214 message : any ;
1315
14- constructor ( private alertService : AlertService ) { }
16+ constructor ( private alertService : AlertService ) {
17+ // subscribe to alert messages
18+ this . subscription = alertService . getMessage ( ) . subscribe ( message => { this . message = message ; } ) ;
19+ }
1520
16- ngOnInit ( ) {
17- this . alertService . getMessage ( ) . subscribe ( message => { this . message = message ; } ) ;
21+ ngOnDestroy ( ) : void {
22+ // unsubscribe on destroy to prevent memory leaks
23+ this . subscription . unsubscribe ( ) ;
1824 }
1925}
You can’t perform that action at this time.
0 commit comments