I have developed a custom wrapper service for the MessageService provided by PrimeNG, rather than directly calling the add()
method within the application. However, I am facing an issue where the code is not functioning as expected and no compile-time or runtime errors are being thrown. I have verified that the code is executing properly through debugging. Interestingly, when I directly use the MessageService, it works fine.
Could it be possible that the MessageService needs to be injected into the component in order to interact with the HTML tag placed in app.component.html
?
Feel free to take a look at the code snippet of the wrapper service below:
import { Injectable } from '@angular/core';
import { MessageService } from 'primeng/api';
@Injectable({
providedIn: 'root'
})
export class ToastService {
constructor(public messageService: MessageService) { }
success(message: string) {
this.messageService.add({ severity: 'success', detail: message });
}
error(message: string) {
this.messageService.add({ severity: 'error', detail: message });
}
}
Cheers!