Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implemented onClick (on toast) event that can be added to ToastOption #90

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 27 additions & 15 deletions src/toast.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,48 @@
// This project is licensed under the terms of the MIT license.
// https://github.com/akserg/ng2-toasty

import { Component, Input, Output, EventEmitter } from '@angular/core';
import { Component, EventEmitter, Input, Output } from '@angular/core';

import { ToastData } from './toasty.service';
import { isFunction } from 'util';

/**
* A Toast component shows message with title and close button.
*/
@Component({
selector: 'ng2-toast',
template: `
<div class="toast" [ngClass]="[toast.type, toast.theme]">
selector: 'ng2-toast',
template: `
<div class="toast" [ngClass]="[toast.type, toast.theme]" (click)="click($event)">
<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" />
<br *ngIf="toast.title && toast.msg"/>
<span *ngIf="toast.msg" class="toast-msg" [innerHtml]="toast.msg | safeHtml"></span>
</div>
</div>`
})
export class ToastComponent {

@Input() toast: ToastData;
@Output('closeToast') closeToastEvent = new EventEmitter();
@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);
}
/**
* 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);
}

/**
* Event handler invokes when user clicks on Toast button.
* This method emit new event into ToastyContainer to close it.
*/
click($event: any) {
$event.preventDefault();
if (this.toast.onClick && isFunction(this.toast.onClick)) {
this.toast.onClick.call(this, this.toast);
}
}
}
Loading