Created
August 7, 2018 17:31
-
-
Save adrianfaciu/c08dfb6daa20092b4f527cbcb3180b1e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Component, OnInit, OnDestroy } from '@angular/core'; | |
import { ToastData } from './toast-config'; | |
import { ToastRef } from './toast-ref'; | |
@Component({ | |
selector: 'app-toast', | |
templateUrl: './toast.component.html', | |
}) | |
export class ToastComponent implements OnInit, OnDestroy { | |
iconType: string; | |
private intervalId: number; | |
constructor(readonly data: ToastData, readonly ref: ToastRef) { | |
this.iconType = data.type === 'success' ? 'done' : data.type; | |
} | |
ngOnInit() { | |
this.intervalId = setTimeout(() => this.close(), 5000); | |
} | |
ngOnDestroy() { | |
clearTimeout(this.intervalId); | |
} | |
close() { | |
this.ref.close(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment