Create component to specific module with Angular-CLI

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

    I didn't find an answer that showed how to use the cli to generate a component inside a top level module folder, and also have the component automatically added the the module's declaration collection.

    To create the module run this:

    ng g module foo
    

    To create the component inside the foo module folder and have it added to the foo.module.ts's declaration collection run this:

    ng g component foo/fooList --module=foo.module.ts
    

    And the cli will scaffold out the module and component like this:

    --EDIT the new version of the angular cli behaves differently. 1.5.5 doesn't want a module file name so the command with v1.5.5 should be

    ng g component foo/fooList --module=foo
    

提交回复
热议问题