Hi Guyz,
Thank you for such a great package.
I have ngx-toastr package installed on my project but I am not using it right now. so I have no export that module in my app component. Once I run the application I am getting this error:
core.js:4002 ERROR Error: Uncaught (in promise): NullInjectorError: StaticInjectorError(AppModule)[InjectionToken ToastConfig]:
StaticInjectorError(Platform: core)[InjectionToken ToastConfig]:
NullInjectorError: No provider for InjectionToken ToastConfig!
NullInjectorError: StaticInjectorError(AppModule)[InjectionToken ToastConfig]:
StaticInjectorError(Platform: core)[InjectionToken ToastConfig]:
Once I import:
import { ToastrModule } from 'ngx-toastr';
ToastrModule.forRoot({
timeOut: 5000,
positionClass: 'toast-bottom-center',
preventDuplicates: true,
closeButton: true,
progressBar: true,
maxOpened: 1,
autoDismiss: true,
enableHtml: true
}),
then that is fine. As I am planning to use in the future.
Do I need to import it?
What?
@sonusindhu Are you importing it in the App Module?
@scttcper I have observed that when I import the module in any lazy loaded module I am getting the same error that @sonusindhu has mentioned. Importing it in the app module works fine.
Does the import work only in AppModule?
I can confirm that I get the same error when attempting to import the ToastrModule inside of a lazy loaded feature module.
Yeah I would assume this module has problems being lazy loaded because of the “entryCompnents”
is there any workarounds for this? this is a critical bug atm and I cannot use toasts at all inside lazy loaded modules
also note that this only happens after an ng build (at least for me)
does anyone have a small reproduction?
yes the import will only work in app.module and not in any lazy loaded modules.
Been almost a Year and seems this issue still exists...
@Vaaljan whats the fix?
@scttcper I think the problem has to do with the version of nxg-toastr.
I was using 12.1.0 with Angular 8 which seems incompatible.
So I downgraded to 11.3.3 on Angular 8
Also had to make sure that the import into the lazy module only happens once like in the AppModule.
Most helpful comment
yes the import will only work in
app.moduleand not in any lazy loaded modules.