最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

javascript - In angular2 is it possible to import CommonModule and RouterModule in a global place for app speed - Stack Overflow

matteradmin9PV0评论

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
 |  Show 5 more ments

1 Answer 1

Reset to default 2

You 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

Post a comment

comment list (0)

  1. No comments so far