我开始使用angular-cli,我已经阅读了很多关于我想做什么的答案…没有成功,所以我来到这里。
是否有一种方法可以为新模块创建组件?
例如:ng g module newModule
如何将该组件添加到newModule中??
因为angular-cli的默认行为是把所有新组件放到app.module中。我想选择我的组件将在哪里,这样我就可以创建单独的模块,而不会有我所有的组件在app.module。这是可能的使用angular-cli或我必须手动这样做?
我开始使用angular-cli,我已经阅读了很多关于我想做什么的答案…没有成功,所以我来到这里。
是否有一种方法可以为新模块创建组件?
例如:ng g module newModule
如何将该组件添加到newModule中??
因为angular-cli的默认行为是把所有新组件放到app.module中。我想选择我的组件将在哪里,这样我就可以创建单独的模块,而不会有我所有的组件在app.module。这是可能的使用angular-cli或我必须手动这样做?
当前回答
您可以尝试下面的命令,该命令描述了
ng -> Angular
g -> Generate
c -> Component
-m -> Module
然后你的命令会像这样:
ng g c user/userComponent -m user.module
其他回答
首先运行ng g module newModule . 然后执行ng g component newModule/newModule——flat命令
使用这个简单的命令:
ng g c users/userlist
users:您的模块名。
userlist:你的组件名。
如果需要同时创建组件和模块,可以使用命令
ng g m components/my-control && ng g c $_
这将在同一个目录中创建一个模块和组件,默认情况下,组件将被添加到closed模块中
对于Angular v4及以上版本,只需使用:
ng g c componentName -m ModuleName
您可以尝试下面的命令,该命令描述了
ng -> Angular
g -> Generate
c -> Component
-m -> Module
然后你的命令会像这样:
ng g c user/userComponent -m user.module