You might remember you helped me last week. I've been able to overcome that issue with your guidance, thank you.
I am now trying to implement buttons/actions on the toast.
Then in the service, I've adapted your code to take Action EventType and showButtons parameter:
actionToast(title: string, message: string) {
this._toastEvents.next({
title: title,
message: message,
type: EventTypes.Action,
icon: "../../../../assets/img/action-toast.png",
errorCode: "",
showButtons: true
});
}
<div
#toastElement
class="toast fade mt-5"
[ngClass]="type"
role="alert"
aria-live="assertive"
aria-atomic="true"
style="width: 500px;"
>
<div class="toast-header">
<img src={{icon}} class="rounded me-2" alt="toast icon" >
<strong class="me-auto">{{title}}</strong>
<button type="button" class="btn-close" aria-label="Close" (click)="hide()"></button>
</div>
<div class="toast-body" style="padding-bottom: 40px;">{{message}}</div>
<div> {{errorCode}}</div>
<div>
<button type="button" *ngIf="showButtons" (click)="yes()">Yes</button>
<button type="button" *ngIf="showButtons" (click)="no()">No</button>
</div>
</div>
I would like to emit the Yes and No events back to the original calling component via the ToastService. I have added
@Output() onYes: EventEmitter<any> = new EventEmitter();
.
.
.
yes() {
this.onYes.emit();
this.hide();
}
.
.
.
But I am not sure how to "listen" to the emitter from the ToastService. Any suggestions?