I have these two imports almost on every ponents module:
import { CommonModule } from '@angular/mon';
import { RouterModule } from '@angular/router';
Is it possible to only have them imported to the global appponent / module where they can be shared?
I'm wanting to be more efficient with my imports because it seems to be effecting my app loading.
Currently my app takes 4 seconds to load and I believe its because of the imports. I have many and want to refactor how I use them.
Also, I'm open to other ideas on how best to import.
My overall goal is to speed up my app down to 2 seconds by doing less imports on all my ponents.
I have these two imports almost on every ponents module:
import { CommonModule } from '@angular/mon';
import { RouterModule } from '@angular/router';
Is it possible to only have them imported to the global app.ponent / module where they can be shared?
I'm wanting to be more efficient with my imports because it seems to be effecting my app loading.
Currently my app takes 4 seconds to load and I believe its because of the imports. I have many and want to refactor how I use them.
Also, I'm open to other ideas on how best to import.
My overall goal is to speed up my app down to 2 seconds by doing less imports on all my ponents.
Share Improve this question asked Dec 5, 2016 at 23:13 AngularMAngularM 16.6k29 gold badges104 silver badges175 bronze badges 10- What makes you think it's the imports? If speed is an issue, have you looked into AOT pilation? – jonrsharpe Commented Dec 5, 2016 at 23:14
- My app when I run it always has a delay of four seconds on load and refresh. – AngularM Commented Dec 5, 2016 at 23:16
- That answers neither question... – jonrsharpe Commented Dec 5, 2016 at 23:17
- I've had a look at that and it looks hard to implement. I'm new to angular 2. I'm using an angular 2 app with typescript and systemjs currently – AngularM Commented Dec 5, 2016 at 23:19
- "My overall goal is to speed up my app down to 2 seconds" - OK! "by doing less imports" - see above. What if you do fewer imports and performance doesn't improve? "it looks hard to implement" - that doesn't mean it isn't worth doing, if you have a specific performance issue. – jonrsharpe Commented Dec 5, 2016 at 23:20
1 Answer
Reset to default 2You can create a shared module and export all the modules or ponents you want to use in the application, then all you need is just to import that shared module.
That's how you can create a shared module: SharedModule