Skip to content

Instantly share code, notes, and snippets.

@adrianfaciu
Created August 7, 2018 17:31
Show Gist options
  • Save adrianfaciu/c08dfb6daa20092b4f527cbcb3180b1e to your computer and use it in GitHub Desktop.
Save adrianfaciu/c08dfb6daa20092b4f527cbcb3180b1e to your computer and use it in GitHub Desktop.
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