angular-cli icon indicating copy to clipboard operation
angular-cli copied to clipboard

default module choice for new component generation

Open hamedbaatour opened this issue 9 years ago • 6 comments

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.

hamedbaatour avatar May 14 '17 11:05 hamedbaatour

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 avatar May 14 '17 13:05 clydin

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

hamedbaatour avatar May 14 '17 13:05 hamedbaatour

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 avatar May 14 '17 14:05 clydin

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

hamedbaatour avatar May 14 '17 14:05 hamedbaatour

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

veton avatar Jun 02 '19 13:06 veton

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.