[英]ngModule import module for entire app?
I'm upgrading my app to angular2 RC and I have a question about ngModule. 我正在将我的应用程序升级到angular2 RC,我对ngModule有疑问。
Lets say I use some componentsModule that has all kind of components that I want to use around my app. 让我说我使用一些componentsModule,它包含我想在我的应用程序中使用的所有类型的组件。
Why would I need to import them in every module separately? 为什么我需要分别在每个模块中导入它们? Why cant I just tell the appModule - "hi make sure everyone gets this."
为什么我不能告诉appModule - “嗨,确保每个人都能得到这个。”
Wont requiring that module over and over again in each module that uses him is just a waste of resources ? 在使用他的每个模块中不要一遍又一遍地要求该模块只是浪费资源? Or is angular2 uses them as singletons ?
或者angular2使用它们作为单身人士? and if so cant that be a problem ?
如果这样不能成为一个问题? - What If I do need new insentces
- 如果我确实需要新的异议
Modules are just a way for Angular's compiler to tell, which components it should expect when going through the templates. 模块只是Angular编译器告诉的一种方式,它在通过模板时应该期望哪些组件。
Ideally, you want your AppModule to be clean and only import what it needs to bootstrap the page. 理想情况下,您希望AppModule干净并只导入引导页面所需的内容。 Next, you import (or route to lazy-loaded modules) your feature modules, which make up your application.
接下来,导入(或路由到延迟加载的模块)构成应用程序的功能模块。
In case you often have one component in many different templates, you can create a SharedModule, which will declare the most common components and pipes in your application, and import that shared module in your feature modules. 如果您经常在许多不同的模板中有一个组件,则可以创建一个SharedModule,它将声明应用程序中最常见的组件和管道,并在功能模块中导入该共享模块。
When Angular 2 compiles your feature module and finds a component from a shared module, it will know how to compile it since you imported that module. 当Angular 2编译您的要素模块并从共享模块中找到一个组件时,它将知道在您导入该模块后如何编译它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.