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

I have these two imports almost on every ponents module:import { CommonModule } from '@angularmon

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

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745627887a4636919.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信