我开始使用 angular-cli 并且我已经阅读了很多内容来找到关于我想做的事情的答案……没有成功,所以我来到了这里。
有没有办法为新模块创建组件?
例如: ng g module newModule
ng g component newComponent
(如何将此组件添加到newModule??)
因为 angular-cli 默认行为是将所有新组件放入 app.module
中。我想选择我的组件的位置,这样我就可以创建单独的模块并且不会将所有组件都放在 app.module
中。可以使用 angular-cli 来做到这一点,还是我必须手动做到这一点?
原文由 Elmer Dantas 发布,翻译遵循 CC BY-SA 4.0 许可协议
要将组件创建为模块的一部分,您应该
ng g module newModule
生成模块,cd newModule
将目录更改为newModule
文件夹ng g component newComponent
创建一个组件作为模块的子模块。更新:角 9
现在,您在生成组件时所在的文件夹并不重要。
ng g module NewModule
生成模块。ng g component new-module/new-component
创建新组件。注意:当 Angular CLI 看到 new-module/new-component 时,它会理解并翻译大小写以匹配
new-module -> NewModule
和new-component -> NewComponent
。一开始可能会让人感到困惑,因此简单的方法是将#2中的名称与模块和组件的文件夹名称相匹配。