-
Notifications
You must be signed in to change notification settings - Fork 358
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow import ToastrModule without forRoot #415
Comments
+1 for this. I'm wrapping your module and adding some defaults for our internal components library. Adding this in root app forces this package to be directly installed whereas I simply want this as a dependency of my custom lib so end developers install 1 package vs 10. |
The main reason this isn't currently allowed is because this can cause unexpected behavior if you try to change the global config in 2 different modules. If you call |
Hi @yarrgh, while your explanation does make sense, why not go the route of something like ng-bootstrap where you have only the base module declaring with This gives the base module the ability to set the global config, while the other modules simply use the global config? If you have a look here they explain it: https://ng-bootstrap.github.io/#/getting-started. |
I see what you mean. Maybe instead of protecting against having Just curious as to why you want to import ToastrModule in a shared module. Are you using any of the component/directives in other modules? |
I have a project in which my notification service is in a shared module. My ToastrModule.forRoot() import is in the shared module only. When I start the app (that consumes the shared module). When I start my app, I get this error message: Error: ToastrModule is already loaded. It should only be imported in your application's main module. However, I am only loading the shared module once. I would hope this can get fixed soon. |
+1 I have my interceptors in my core module, as part of my error interceptor I want it to throw a toastr error on any http error response. I can't seem to get it working although I am new to splitting my application into modules. If I add toastr to my interceptor I get: NullInjectorError: No provider for ToastrService!. When I add ToastrModule to my core.module I get 'ToastrModule is already loaded' (it's not imported in app.module). |
@chrisjau Move your import from your shared module (or wherever it is being imported) into your core module. Honestly, I'm having a hard time understanding the benefit of allowing When you call
|
It seems irrespective of whether forRoot is used or not. If I remove the references below, and only add toastr to a lazy loaded feature module (by directly invoking it on subscribe() it works). Again I can't discount i'm doing something wrong. I have no shared module at this stage. Core.module is eager loaded in app.module and the interceptor lives in core.module so there are no lazy loaded modules in play with the setup I desire. If you aren't sure why it's breaking I don't want to waste any more of your time. thanks core.module.ts error interceptor: app.module imports: [ CoreModule.forRoot() ] |
@chrisjau your issue is different from this issue. I believe the issue you're seeing is caused from ToastrService not being available yet when trying to inject into your interceptor. See #179 (comment) for an example of how to fix your issue. If you're still having issues, open a new issue. |
I have two projects in application. I have added ToastrModule in one app's CoreModule & export it. it is working fine. But when I added ToastrModule in another app's CoreModule, it gives error that (It is already imported. Add ToastrModule to Application main module.). |
Do they share a core module at all? |
@yarrgh, No both projects have different CoreModule |
🎉 This issue has been resolved in version 9.0.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Hi |
Hi, I've found that your library doesn't allow importing ToastrModule multiple times.
I would like to know why you don't support this feature. Most of the hybrids modules I've seen allow importing declarations on SharedModule and use forRoot for providers. Your module seems to do the same thing but the code on it's constructor disallows this feature.
The text was updated successfully, but these errors were encountered: