Angular-cli: default module choice for new component generation

Created on 14 May 2017  路  6Comments  路  Source: angular/angular-cli

Bug Report or Feature Request (mark with an x)

- [ ] bug report -> please search issues before submitting
- [x] feature request

When generating a new component using the angular CLI with the presence of another module like a Material2 NgModule that imports all of the Angular Material components I have to add --module every time to include the new component in my app.module.ts but I am developing a very large angular app and the process became really tedious so can we have a default module feature that enables us to set a default module when creating a new project using the CLI.

Most helpful comment

The CLI searches the directory hierarchy to find the nearest module. In this context, a _default_ module would not be entirely relevant and, in fact, counterproductive. The advantage to this process becomes apparent when dealing with feature modules; wherein a component generated within a feature will automatically be added to the relevant feature module.

In general, it is recommended to create a new directory for each module.

All 6 comments

The CLI doesn't try to guess which module you want to own the component. If you have more than one module in a directory, you will need to use the "--module" option to specify the desired module.

@clydin is there a way I can set a default module without typing the same thing over and over again?

The CLI searches the directory hierarchy to find the nearest module. In this context, a _default_ module would not be entirely relevant and, in fact, counterproductive. The advantage to this process becomes apparent when dealing with feature modules; wherein a component generated within a feature will automatically be added to the relevant feature module.

In general, it is recommended to create a new directory for each module.

@clydin thanks for the explanation and yeah I think creating a new directory for each module will be a better choice in this case.

A workaround is to leave the default module in a root and moving non-default modules into a subfolder.
Example:

  • [app]

    • [ssr]

    • app.server.module.ts

    • app.module.ts

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

_This action has been performed automatically by a bot._

Was this page helpful?
0 / 5 - 0 ratings