projects/ngx-toastn/src/lib/ngx-toast.component.ts
A Toast component shows message with title and close button.
| selector | ngx-toast |
| templateUrl | ngx-toast.component.html |
Methods |
Inputs |
Outputs |
toast
|
Type: |
closeToast
|
$event type: EventEmitter
|
| close | ||||||
close($event: any)
|
||||||
|
Event handler invokes when user clicks on close button. This method emit new event into ToastyContainer to close it.
Parameters :
Returns :
void
|
import { Component, Input, Output, EventEmitter } from '@angular/core';
import { ToastData } from './ngx-toastn.service';
/**
* A Toast component shows message with title and close button.
*/
@Component({
selector: 'ngx-toast',
templateUrl: 'ngx-toast.component.html'
})
export class NgxToastComponent {
@Input() toast: ToastData;
@Output('closeToast') closeToastEvent = new EventEmitter();
/**
* Event handler invokes when user clicks on close button.
* This method emit new event into ToastyContainer to close it.
*/
close($event: any) {
$event.preventDefault();
this.closeToastEvent.next(this.toast);
}
}
<div class="toast" [ngClass]="[toast.type, toast.theme]">
<div *ngIf="toast.showClose" class="close-button" (click)="close($event)"></div>
<div *ngIf="toast.title || toast.msg" class="toast-text">
<span *ngIf="toast.title" class="toast-title" [innerHTML]="toast.title | safeHtml"></span>
<br *ngIf="toast.title && toast.msg" />
<span *ngIf="toast.msg" class="toast-msg" [innerHtml]="toast.msg | safeHtml"></span>
</div>
</div>