如题,今天按照官方说法搭了ng的demo,但是有一点不明白。
在网上看有些人是把ngmodule作为一个容器来用(比如首页为一个ngmodule,后台登录页为一个ngmodule)。
然后通过这个module级别的容器组织页面结构,和引入的组建和服务。
我就新建了个homemodule(里面声明了一个组件,组件的selector是test1)组织首页的内容,然后在根module中imports了。
然后买根组件的bootstrap组件中写入了<test1></test1>为什么它告诉我声明是错误的?一定要在根组件中声明这个组件吗?那不是项目大起来会乱成一片
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