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
if you want to create along with your module try this
ng generate m module_name --routing && ng generate c component_name
ng g component nameComponent --module=app.module.ts
1.- Create your feature module as usual.
ng generate module dirlevel1/module-name
2.- You can specify the ROOT PATH of your project in --module ( only in --module, (/) root points to your PROJECT ROOT and IS NOT THE SYSTEM ROOT!!!)
ng generate component dirlevel1/component-name --module /src/app/dirlevel1/module-name.module.ts
Real Example:
ng generate module stripe/payment-methods-list
ng generate component stripe/payment-methods-list --module=/src/app/stripe/payment-methods-list/payment-methods-list.module.ts
Output:
CREATE src/app/stripe/payment-methods-list/payment-methods-list.component.scss (0 bytes)
CREATE src/app/stripe/payment-methods-list/payment-methods-list.component.html (39 bytes)
CREATE src/app/stripe/payment-methods-list/payment-methods-list.component.spec.ts (768 bytes)
CREATE src/app/stripe/payment-methods-list/payment-methods-list.component.ts (322 bytes)
UPDATE src/app/stripe/payment-methods-list/payment-methods-list.module.ts (311 bytes)
[OK] Generated component!
Tested with Angular CLI: 9.1.4
If you have multiple apps declared in .angular-cli.json ( e.g. in case working on feature module)
"apps": [{
"name": "app-name",
"root": "lib",
"appRoot": ""
}, {...} ]
You can :
ng g c my-comp -a app-name
-a stands for --app (name)
this is what worked for me :
1 --> ng g module new-module
2 --> ng g c new-module/component-test --module=new-module/new-module.module.ts
If you want to generate a component without its directory use --flat
flag.
I use this particular command for generating components inside a module.
ng g c <module-directory-name>/<component-name>
This command will generate component local to the module. or You can change directory first by typing.
cd <module-directory-name>
and then create component.
ng g c <component-name>
Note: code enclosed in <> represent user specific names.