Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to generate multiple Angular components using single angular-cli command like ng generate component comp1, comp2, comp3?

Tags:

I need to create ten Angular components like comp1, comp2, comp3, comp4, ..., comp10. So I need to execute same command for ten times for each component like ng g c comp1, ng g c comp2, etc.

Is there any option to generate multiple angular components using single angular-cli command like ng g c comp1, comp2, comp3.

like image 325
ranjit redekar Avatar asked Jul 05 '18 06:07

ranjit redekar


People also ask

Can we create multiple components in Angular?

Every component must be declared in one—and only one—Angular module. Open app.

How many files in total get generated when you generate a new component in Angular?

Inside that directory, four files are created: A CSS file for the component styles. An HTML file for the component template.

Does Ng generate component create folder?

We can use ng generate component command to create component in sub-directory or specific folder.


2 Answers

Well, there is nothing as of now by Angular CLI to create multiple components. But this can be done trivially in any shell.

Run this command into your bash shell -

for i in comp1 comp2; do ng g c "${i}"; done

Special thanks to Ingo Bürk's answer

like image 78
Pardeep Jain Avatar answered Oct 03 '22 07:10

Pardeep Jain


Microsoft Windows variants

In root:

for %n in (component-name-1, component-name-2, ...) do ng g c %n

In module:

for %n in (component-name-1, component-name-2, ...) do ng g c module-name/%n

In module, without tests:

for %n in (component-name-1, component-name-2, ...) do ng g c module-name/%n --skipTests=true

Angular - ng generate

Windows CMD FOR command reference

like image 30
urusai_na Avatar answered Oct 03 '22 07:10

urusai_na