11import { CommonModule } from '@angular/common' ;
22import { DeprecateProperty } from '../core/deprecateDecorators' ;
33import {
4+ ChangeDetectorRef ,
45 Component ,
56 ElementRef ,
67 EventEmitter ,
78 HostBinding ,
89 Inject ,
910 Input ,
1011 NgModule ,
11- OnDestroy ,
12- OnInit ,
1312 Optional ,
1413 Output ,
1514} from '@angular/core' ;
1615import { IgxNavigationService , IToggleView } from '../core/navigation' ;
16+ import { IgxToggleDirective } from '../directives/toggle/toggle.directive' ;
1717import { IgxOverlayOutletDirective } from '../directives/toggle/toggle.directive' ;
1818import {
1919 OverlaySettings ,
@@ -60,7 +60,8 @@ export type IgxToastPosition = keyof typeof IgxToastPositionEnum;
6060 selector : 'igx-toast' ,
6161 templateUrl : 'toast.component.html' ,
6262} )
63- export class IgxToastComponent implements IToggleView , OnInit , OnDestroy {
63+ export class IgxToastComponent extends IgxToggleDirective
64+ implements IToggleView {
6465 private _isVisible = false ;
6566
6667 /**
@@ -201,7 +202,6 @@ export class IgxToastComponent implements IToggleView, OnInit, OnDestroy {
201202 * ```
202203 * @memberof IgxToastComponent
203204 */
204- @HostBinding ( 'class.igx-toast--active' )
205205 @Input ( )
206206 public get isVisible ( ) {
207207 return this . _isVisible ;
@@ -262,7 +262,7 @@ export class IgxToastComponent implements IToggleView, OnInit, OnDestroy {
262262 * @memberof IgxToastComponent
263263 */
264264 public get element ( ) {
265- return this . elementRef . nativeElement ;
265+ return this . _element . nativeElement ;
266266 }
267267
268268 /**
@@ -276,16 +276,14 @@ export class IgxToastComponent implements IToggleView, OnInit, OnDestroy {
276276 */
277277 private timeoutId : number ;
278278
279- /**
280- * @hidden
281- */
282- private overlayId : string ;
283-
284279 constructor (
285- private elementRef : ElementRef ,
286- @Optional ( ) private navService : IgxNavigationService ,
287- @Inject ( IgxOverlayService ) private overlayService : IgxOverlayService
288- ) { }
280+ private _element : ElementRef ,
281+ cdr : ChangeDetectorRef ,
282+ @Optional ( ) navService : IgxNavigationService ,
283+ @Inject ( IgxOverlayService ) overlayService : IgxOverlayService
284+ ) {
285+ super ( _element , cdr , overlayService , navService ) ;
286+ }
289287
290288 /**
291289 * Shows the toast.
@@ -311,29 +309,29 @@ export class IgxToastComponent implements IToggleView, OnInit, OnDestroy {
311309 closeOnEscape : false ,
312310 closeOnOutsideClick : false ,
313311 modal : false ,
314- outlet : this . outlet
312+ outlet : this . outlet ,
315313 } ;
316314
317315 if ( message !== undefined ) {
318316 this . toastMessage = message ;
319317 }
320318
321- this . overlayId = this . overlayService . attach (
322- this . elementRef ,
323- overlaySettings
324- ) ;
325-
326- this . onShowing . emit ( this ) ;
327- this . _isVisible = true ;
319+ this . onOpening . subscribe ( ( ) => {
320+ this . isVisible = true ;
321+ this . onShowing . emit ( this ) ;
322+ } ) ;
328323
329324 if ( this . autoHide ) {
330325 this . timeoutId = window . setTimeout ( ( ) => {
331326 this . hide ( ) ;
332327 } , this . displayTime ) ;
333328 }
334329
335- this . overlayService . show ( this . overlayId ) ;
336- this . onShown . emit ( this ) ;
330+ super . open ( overlaySettings ) ;
331+
332+ this . onOpened . subscribe ( ( ) => {
333+ this . onShown . emit ( this ) ;
334+ } ) ;
337335 }
338336
339337 /**
@@ -344,11 +342,18 @@ export class IgxToastComponent implements IToggleView, OnInit, OnDestroy {
344342 * @memberof IgxToastComponent
345343 */
346344 public hide ( ) : void {
347- this . onHiding . emit ( this ) ;
348- this . _isVisible = false ;
349- this . onHidden . emit ( this ) ;
350- this . overlayService . hide ( this . overlayId ) ;
351345 clearInterval ( this . timeoutId ) ;
346+
347+ this . onClosing . subscribe ( ( ) => {
348+ this . isVisible = false ;
349+ this . onHiding . emit ( this ) ;
350+ } ) ;
351+
352+ super . close ( ) ;
353+
354+ this . onClosed . subscribe ( ( ) => {
355+ this . onHidden . emit ( this ) ;
356+ } ) ;
352357 }
353358
354359 /**
@@ -375,25 +380,7 @@ export class IgxToastComponent implements IToggleView, OnInit, OnDestroy {
375380 * @memberof IgxToastComponent
376381 */
377382 public toggle ( ) {
378- this . _isVisible ? this . close ( ) : this . open ( ) ;
379- }
380-
381- /**
382- * @hidden
383- */
384- public ngOnInit ( ) {
385- if ( this . navService && this . id ) {
386- this . navService . add ( this . id , this ) ;
387- }
388- }
389-
390- /**
391- * @hidden
392- */
393- public ngOnDestroy ( ) {
394- if ( this . navService && this . id ) {
395- this . navService . remove ( this . id ) ;
396- }
383+ super . toggle ( ) ;
397384 }
398385}
399386
0 commit comments