我正在使用Angular 4和Angular CLI,我可以用下面的命令创建一个新组件。
E:\HiddenWords>ng generate component plainsight
但我需要在plainsight内生成一个子组件。有办法用Angular CLI来实现吗?
我正在使用Angular 4和Angular CLI,我可以用下面的命令创建一个新组件。
E:\HiddenWords>ng generate component plainsight
但我需要在plainsight内生成一个子组件。有办法用Angular CLI来实现吗?
当前回答
我在上面的答案上没有任何运气(包括-平坦),但对我来说有用的是:
cd path/to/specific/directory
从那里,我运行ng g c mynewcomponent
其他回答
我在上面的答案上没有任何运气(包括-平坦),但对我来说有用的是:
cd path/to/specific/directory
从那里,我运行ng g c mynewcomponent
ng g c folderName/SubFolder/.../componentName --spec=false
假设你想在一个模块Box中创建一个组件Container,模块已经创建好了,并且存在于它自己的文件夹src/app/ Box中。
您可以这样做——当被要求提供组件名称时,提供组件的路径和组件名称。
ng g c -m box
? What name would you like to use for the component? box/Container
CREATE src/app/box/container/container.component.scss (0 bytes)
CREATE src/app/box/container/container.component.html (24 bytes)
CREATE src/app/box/container/container.component.spec.ts (647 bytes)
CREATE src/app/box/container/container.component.ts (288 bytes)
UPDATE src/app/box/box.module.ts (286 bytes)
打开一个终端窗口,导航到Angular项目的根目录。创建文件夹
运行如下命令在指定文件夹中生成新组件:
ng generate component <folderName>/<componentName>
例如,如果你想在名为“components”的文件夹中创建一个名为“myComponent”的新组件,命令将是:
ng generate component components/myComponent
使用'ng generate component ./target_directory/Component_Name'