I want to display a PrimeNG dynamic dialog, if the user is unauthorized (status == 401). But if I want to open the dialog, I get an error:
NullInjectorError: No provider for DialogService!
I solved this by adding the DialogService to the root's module providers:
@NgModule({
declarations: [],
imports: [],
entryComponents: [],
providers: [
DialogService
]
...
But I'm not sure if this is the correct way, because as written in the official documentation, every component should have his own DialogService provider. But because I need the DialogService in an other Service (UnauthorizedHttpInterceptor) I have to include the DialogService into the root providers list. Is that correct?
Every other component which has his own provider:
@Component({
templateUrl: './dynamicdialogdemo.html',
providers: [DialogService]
})
will use his own instance.
So there shouldn't be any problem with my solution? If so, what is the correct way to provide the DialogService instance into the Interceptor?
My main aim is to avoid collidings of the multiple DialogService components, in order to open/close multiple dialogs successfully.