是否可以使用单个angular-cli命令生成多个Angular组件,例如ng generate component comp1,comp2,comp3?

ran*_*kar 7 angular-cli angular angular-cli-v6

我需要创建十个Angular组件,如comp1,comp2,comp3,comp4,...,comp10.所以我需要为每个组件执行相同的命令十次,如ng gc comp1,ng gc comp2等.

是否有任何选项可以使用单个angular-cli命令生成多个角度分量,如ng gc comp1,comp2,comp3.

Par*_*ain 9

嗯,目前Angular CLI没有任何内容可以创建多个组件.但这可以在任何shell中轻松完成.

将此命令运行到bash shell中 -

for i in comp1 comp2; do ng g c "${i}"; done
Run Code Online (Sandbox Code Playgroud)

特别感谢IngoBürk的回答

  • 所以你从 Github 复制了我的确切答案,甚至包括措辞,甚至不提? (4认同)

小智 7

如果您不想创建脚本,这里有一个可行的方法

  1. 打开记事本或任何文本编辑器
  2. 使用如下语法编写组件名称:
  ng 气相色谱组件/接触
  ng GC 组件/登录
  ng GC 组件/注册
  ng GC 组件/仪表板
  1. 复制上面的内容并粘贴到 CLI 中(我使用了 Git bash)。它将一一执行,没有任何忙乱。您还可以添加特定于组件的参数


uru*_*_na 6

Microsoft Windows 变体

在根:

for %n in (component-name-1, component-name-2, ...) do ng g c %n
Run Code Online (Sandbox Code Playgroud)

在模块中:

for %n in (component-name-1, component-name-2, ...) do ng g c module-name/%n
Run Code Online (Sandbox Code Playgroud)

在模块中,没有测试:

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

Angular - ng 生成

Windows CMD FOR命令参考