我开始使用angular cli,我已经读了很多关于我想做什么的答案...没有成功,所以我来到这里.

有没有办法为新模块创建组件?

e、 g:ng g module newModule

ng g component newComponent(如何将此组件添加到新模块??)

因为默认行为是将所有新组件放入app.module中.我想 Select 我的组件将在哪里,这样我就可以创建单独的模块,而不会让我的所有组件都在app.module之内.可以使用angular cli执行此操作,还是必须手动执行此操作?

推荐答案

要创建组件作为模块的一部分,您应该

  1. ng g module newModule生成一个模块,
  2. 切换到cd newModule目录
  3. ng g component newComponent创建一个组件作为模块的子组件.

更新:Angular 9

现在,生成组件时,您所在的文件夹无关紧要.

  1. ng g module NewMoudle生成一个模块.
  2. ng g component new-module/new-component来创建NewComponent.

Note: When the Angular CLI sees new-module/new-component, it understands and translates the case to match new-module -> NewModule and new-component -> NewComponent. It can get confusing in the beginning, so easy way is to match the names in #2 with the folder names for the module and component.

Typescript相关问答推荐

具有条件通用props 的react 类型脚本组件错误地推断类型

在角形加载组件之前无法获取最新令牌

在将对象从一个对象转换成另一个对象时,可以缩小对象的键吗?

异步动态生成Playwright测试,显示未找到测试

如何在TypeScript中将一个元组映射(转换)到另一个元组?

从子类构造函数推断父类泛型类型

分解对象时出现打字错误

如何在Reaction Query Builder中添加其他字段?

是否可以强制静态方法将同一类型的对象返回其自己的类?

有没有可能创建一种类型,强制在TypeScrip中返回`tyPeof`语句?

为什么TS2339;TS2339;TS2339:类型A上不存在属性a?

在Reaction中折叠手风琴

Typescript,如何在通过属性存在过滤后重新分配类型?

垫子工具栏不起作用的Angular 布线

有没有一种方法可以防止我的组件包在其中安装样式组件'; node 模块中的s目录

如何创建允许使用带有联合类型参数的Array.from()的TS函数?

如何通过nx找到所有受影响的项目?

如何使用动态生成的键和值定义对象的形状?

从 npm 切换到 pnpm 后出现Typescript 错误

redux-toolkit、createAsyncThunk 错误