Create component to specific module with Angular-CLI

后端 未结 26 1632
既然无缘
既然无缘 2021-01-29 19:46

I\'m starting to use angular-cli and I\'ve already read a lot to find an answer about what I want to do...no success, so I came here.

Is there a way to create a componen

26条回答
  •  说谎
    说谎 (楼主)
    2021-01-29 20:04

    Not sure if maybe Alexander Ciesielski's answer was correct at the time of writing, but I can verify that this no longer works. It doesn't matter which directory in the project you run the Angular CLI. If you type

    ng g component newComponent
    

    it will generate a component and import it into the app.module.ts file

    The only way you can use CLI to automatically import it into another module is by specifying

    ng g component moduleName/newComponent
    

    where moduleName is a module you've already defined in your project. If the moduleName doesn't exist, it'll put the component in moduleName/newComponent directory but still import it into app.module

提交回复
热议问题