在我们的angular2项目中,我们将所有模型的ts文件放在特定文件夹中:/ app/common/model/*。 我可以在带有亲属路径的组件中调用它们,但这非常费力。 所以2解决方案,最好是自定义路径:StackOverflow: Relative Paths for SystemJS & ES module imports。 但我的IDE找不到路径。这里是我的tsconfig:Angular2导入绝对路径或自定义路径(typescript 2)
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"moduleResolution": "node",
"sourceMap": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"removeComments": false,
"noImplicitAny": true,
"suppressImplicitAnyIndexErrors": true,
"outDir": "built",
"baseUrl": ".",
"paths": {
"mymodel/*": [
"app/common/model/*"
]
}
}
}
在我的组件: import { Address } from 'mymodel/address.model';
IDE:[TS]找不到模块.... 我试过带或不带*路径
解决方法二: Stackoverflow: Angular 2, imports between different folders
IDE和编译都OK,以饱满的路径组件: import { Address } from 'common/model/address.model';
而且tsconfig:
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"moduleResolution": "node",
"sourceMap": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"removeComments": false,
"noImplicitAny": true,
"suppressImplicitAnyIndexErrors": true,
"outDir": "built",
"baseUrl": ".",
"paths": {
"*": [
"app/*",
"node_modules/*"
]
}
}
}
但我们对所有型号的页面加载具有404。 也许在systemjs文件中的配置?
在这两种情况下,我认为“outdir”参数是问题,我们错过了一些东西。
非常感谢您的帮助!
问候,
打字稿:2.0.6 角:2.0.0
您正在使用哪种IDE?在我的(IntelliJ/Webstorm)中,我几乎从不输入import:IDE为我添加它。 –
Visual Studio代码。在你的是绝对路径? – lginlap
第一个解决方案与其他IDE一起工作很好......对不起,这是一个虚假问题 – lginlap