@@ -9,9 +9,13 @@ import {
99 Inject ,
1010 Input ,
1111 NgModule ,
12+ OnDestroy ,
13+ OnInit ,
1214 Optional ,
1315 Output ,
1416} from '@angular/core' ;
17+ import { Subject } from 'rxjs' ;
18+ import { takeUntil } from 'rxjs/operators' ;
1519import { IgxNavigationService , IToggleView } from '../core/navigation' ;
1620import { IgxToggleDirective } from '../directives/toggle/toggle.directive' ;
1721import { IgxOverlayOutletDirective } from '../directives/toggle/toggle.directive' ;
@@ -61,7 +65,8 @@ export type IgxToastPosition = keyof typeof IgxToastPositionEnum;
6165 templateUrl : 'toast.component.html' ,
6266} )
6367export class IgxToastComponent extends IgxToggleDirective
64- implements IToggleView {
68+ implements IToggleView , OnInit , OnDestroy {
69+ private d$ = new Subject < boolean > ( ) ;
6570 private _isVisible = false ;
6671
6772 /**
@@ -262,7 +267,7 @@ export class IgxToastComponent extends IgxToggleDirective
262267 * @memberof IgxToastComponent
263268 */
264269 public get element ( ) {
265- return this . element . nativeElement ;
270+ return this . _element . nativeElement ;
266271 }
267272
268273 /**
@@ -277,7 +282,7 @@ export class IgxToastComponent extends IgxToggleDirective
277282 private timeoutId : number ;
278283
279284 constructor (
280- _element : ElementRef ,
285+ private _element : ElementRef ,
281286 cdr : ChangeDetectorRef ,
282287 @Optional ( ) navService : IgxNavigationService ,
283288 @Inject ( IgxOverlayService ) overlayService : IgxOverlayService
@@ -316,14 +321,8 @@ export class IgxToastComponent extends IgxToggleDirective
316321 this . toastMessage = message ;
317322 }
318323
319- this . onOpening . subscribe ( ( ) => {
320- this . isVisible = true ;
321- this . onShowing . emit ( this ) ;
322- } ) ;
323-
324- this . onAppended . subscribe ( ( ) => {
325- this . onShown . emit ( this ) ;
326- } ) ;
324+ this . isVisible = true ;
325+ this . onShowing . emit ( this ) ;
327326
328327 super . open ( overlaySettings ) ;
329328
@@ -343,17 +342,9 @@ export class IgxToastComponent extends IgxToggleDirective
343342 */
344343 public hide ( ) : void {
345344 clearInterval ( this . timeoutId ) ;
346-
347- this . onClosing . subscribe ( ( ) => {
348- this . isVisible = false ;
349- this . onHiding . emit ( this ) ;
350- } ) ;
351-
345+ this . isVisible = false ;
346+ this . onHiding . emit ( this ) ;
352347 super . close ( ) ;
353-
354- this . onClosed . subscribe ( ( ) => {
355- this . onHidden . emit ( this ) ;
356- } ) ;
357348 }
358349
359350 /**
@@ -382,6 +373,27 @@ export class IgxToastComponent extends IgxToggleDirective
382373 public toggle ( ) {
383374 super . toggle ( ) ;
384375 }
376+
377+ /**
378+ * @hidden
379+ */
380+ ngOnInit ( ) {
381+ this . onAppended . pipe ( takeUntil ( this . d$ ) ) . subscribe ( ( ) => {
382+ this . onShown . emit ( this ) ;
383+ } ) ;
384+
385+ this . onClosed . pipe ( takeUntil ( this . d$ ) ) . subscribe ( ( ) => {
386+ this . onHidden . emit ( this ) ;
387+ } ) ;
388+ }
389+
390+ /**
391+ * @hidden
392+ */
393+ ngOnDestroy ( ) {
394+ this . d$ . next ( true ) ;
395+ this . d$ . complete ( ) ;
396+ }
385397}
386398
387399/**
0 commit comments