【问题标题】:Angular project: How can I add modules for each component in a existing tree of components?Angular 项目:如何为现有组件树中的每个组件添加模块?
【发布时间】:2020-11-13 01:27:02
【问题描述】:

我有 angular 10 项目。我创建了一个组件树,例如:

app>main>内容>库

每个文件夹都包含自动生成的文件。例如在主文件夹中存在:

main.component.css
main.component.html
main.component.ts

我想为每个文件夹添加一个模块。 当我尝试它时,生成了一个模块文件,因此添加到文件上方的列表中:

main.module.ts

但是,过了一会儿,我收到了一个错误。 即使我删除文件,该文件夹仍保持红色。 你知道为什么会这样吗?

如何为每个文件夹组件添加一个模块?

【问题讨论】:

  • 请输入您收到的错误信息。

标签: angular file module components


【解决方案1】:

试试这个, ng g module main 在命令提示符下 在运行该命令之前,请确保您位于组件文件夹目录中。 作为, library\content\main> ng g module main

现在:- 上面的命令将做的是 module.ts 将在另一个主文件夹中创建为“main>main>main.module.ts 所以你只需要从那里复制那个 module.ts 文件并将其粘贴到父主目录中。

PS:我假设你的 main.html、main.css、main.ts 文件在主文件夹中。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-02-26
    • 1970-01-01
    • 2013-08-07
    • 2018-12-29
    • 2010-09-13
    • 1970-01-01
    • 2016-11-29
    • 2020-07-28
    相关资源
    最近更新 更多