我开始使用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或我必须手动这样做?
当前回答
如果你已经创建了你的组件而没有指向一个模块,你可以通过将它添加到声明中来直接将它添加到你的应用模块中
@NgModule({
declarations: [
FileManagerDetailsComponent <---this is ur page component
其他回答
使用这个简单的命令:
ng g c users/userlist
users:您的模块名。
userlist:你的组件名。
ng g component nameComponent --module=app.module.ts
ng g c模块
然后在共享模块中创建头组件
ng g c shared/header --module=shared
阅读描述——route https://angular.io/cli/generate#module-command,
为了存档,您必须将该组件模块的路由添加到某个位置,并指定路由名称。
ng generate module component-name --module=any-parent-module --route=route-path
今天我在搭建一个Angular 9应用程序时遇到了这个问题。我得到了“模块不存在错误”每当我添加.module。Ts或.module到模块名。cli只需要模块名,不需要扩展名。假设我有一个模块名:brands.module。ts,我使用的命令是
ng g c path/to/my/components/brands-component -m brands --dry-run
一旦确认文件结构正确,就删除——dry-run。