javascript - In angular2/4, should the container that organizes a page be component or module?
过去多啦不再A梦
过去多啦不再A梦 2017-05-15 17:13:59
0
3
576

As mentioned, I used the ng demo today according to the official statement, but there is one thing I don’t understand.

On the Internet, I saw that some people use ngmodule as a container (for example, the home page is an ngmodule, and the background login page is an ngmodule).

Then organize the page structure, and introduced components and services through this module-level container.

I created a new homemodule (a component is declared in it, and the selector of the component is test1) to organize the content of the homepage, and then imported it in the root module.

Then I wrote <test1></test1> in the bootstrap component of the root component. Why does it tell me that the statement is wrong? Do I have to declare this component in the root component? If the project gets bigger, it will become a mess

过去多啦不再A梦
过去多啦不再A梦

reply all(3)
某草草

Refer to the NG module section of Angular Chinese documentation.
Module includes the main module AppModule, as well as feature module, etc. When the project is complex, the feature module can be used to place multiple components, instructions, services, etc. with the same characteristics. When using a feature module, you need to export the content in your declarations that needs to be exposed to the main Module. The main module needs to import other feature modules

为情所困

Summary in one sentence:
If you are doing a small project, don’t worry about so many, one root module can solve everything;
If you are doing a medium to large project, it is recommended to divide the modules according to business modules.

大家讲道理

bootstrap only needs to be declared in appModule, and the rest can be used as routing to make feature modules

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template