Create component to specific module with Angular-CLI

后端 未结 26 1627
既然无缘
既然无缘 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

    0 讨论(0)
  • 2021-01-29 20:06
    ng g c componentName --module=path-to-your-module-from-src-folder
    

    example:

    ng g c testComponent --module=/src/app/home/test-component/test-component.module
    
    0 讨论(0)
  • 2021-01-29 20:06

    I am having the similar issues with multiple modules in application. A component can be created to any module so before creating a component we have to specify the name of the particular module.

    'ng generate component newCompName --module= specify name of module'
    
    0 讨论(0)
  • 2021-01-29 20:06

    First run ng g module newModule . Then run ng g component newModule/newModule --flat

    0 讨论(0)
  • 2021-01-29 20:07

    Go to module level/we can also be in the root level and type below commands

    ng g component "path to your component"/NEW_COMPONENT_NAME -m "MODULE_NAME"
    

    Example :

    ng g component common/signup/payment-processing/OnlinePayment -m pre-login.module
    
    0 讨论(0)
  • 2021-01-29 20:09

    For Angular v4 and Above, simply use:

    ng g c componentName -m ModuleName
    
    0 讨论(0)
提交回复
热议问题