Angular AOT 组件中的相对路径

标签 angular relative-path aot

我在这里问是因为我无法在网上找到完整的文档。 示例 here太简单了。 我有一个包含多个组件和一些模块的应用程序。用ngc编译后,我有很多错误。我发现修复它们的方法是使用相对路径。 因此,我在所有组件中都使用“moduleId: module.id,”。 但是现在编译器告诉我: ' 找不到名称“模块” '

据我了解,这是因为我为 AoT 声明了以下编译选项:

{
  "compilerOptions": {
    "target": "es5",
   ---> "module": "es2015",
    "moduleResolution": "node",
    "sourceMap": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "removeComments": true,
    "noImplicitAny": true,
    "suppressImplicitAnyIndexErrors": true
  },

  "angularCompilerOptions": {
   "genDir": "aot",
   "skipMetadataEmit" : true
 }
}

而不是使用 "module": "commonjs",。 我该如何解决这个问题?

如何在生成 AOT 构建的同时使用相对路径?

谢谢!

最佳答案

一个快速(也可能是肮脏的)修复方法是将路径直接写为 moduleId 参数中的字符串。

所以代替:

moduleId: module.id

写:

moduleId: 'path/to/my/app/'

这可以在开发期间与组件相对路径一起使用,并且在创建 AoT 包时 ngc 不会提示找不到 module.id。

关于Angular AOT 组件中的相对路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39964779/

相关文章:

本地存储的 Angular 异步问题

angular - 带有 AOT 的延迟加载模块 - TypeError : '' is not a function when served from NGINX

angular - 如何在本地使用谷歌字体而不是在 Angular 4 项目中导入

php - 相对路径不适用于 css 中的图像

python - Django 1.8 : Help making filenames RELATIVE

bundle - 使用相对导入路径时 Aurelia bundle 失败

compilation - 关于可能的 java(或其他内存管理语言)优化的问题

angular - 如何将 Angular 4+(前端)部署到 CDN?

javascript - ngFor 中的下拉列表仅显示第一个列表项

javascript - 如何在JS中从键/值创建字符串数组?