I use ngx-toastr library for showing notifications.This library contains ToastrService
. But, I want to create my own wrapper for this service, because I need different configs for different types of messages. So I have:
@Injectable()
export class NotificationService {
constructor(private toastrService: ToastrService) {
}
public success(message: string, title?: string): void {
this.toastrService.success(message, title);
}
public error(message: string, title?: string): void {
let toastConfig = {
...
};
this.toastrService.error(message, title, toastConfig);
}
public info(message: string, title?: string): void {
let toastConfig = {
...
};
this.toastrService.info(message, title, toastConfig);
}
public warning(message: string, title?: string): void {
this.toastrService.warning(message, title);
}
}
I want to prevent other developers from injecting ToastrService somewhere. If user inject ToastrService to component or other service except of NotificationService
I want to throw error. How can I do this?
Module:
@NgModule({
imports: [
ToastrModule.forRoot(),
],
declarations: [],
providers: [
NotificationService
],
exports: []
})