Par*_*ain 3 view relative-path angular
在搜索时我发现了一些名为moduleId设置模板和CSS文件的相对路径的东西,但我moduleId不确切知道如何在我们的angular2组件中使用?
实际上,问题出在我的文件夹结构中.我从dist文件夹加载我的所有.js文件,而我的视图(.html文件)在src文件夹中.所以当我使用moduleId: module.id像这样的角度从dist文件夹,而不是src文件夹采取路径.
所以这里有人帮我告诉我如何为我的组件angualr2设置自定义moduleId?
我的文件夹结构是这样的.
App
/\
/ \
(.js + .map files)Dist Src(.ts + .html + .css files)
Run Code Online (Sandbox Code Playgroud)
实际编码(工作) -
@Component({
selector: 'class-timing',
templateUrl: 'src/components/TimeTable/class-timing/class-timing.html',
styleUrls: ['src/app.css']
})
Run Code Online (Sandbox Code Playgroud)
修改编码(由于路径不正确而无法工作) -
@Component({
selector: 'class-timing',
templateUrl: 'class-timing.html',
moduleId: module.id,
styleUrls: ['src/app.css']
})
Run Code Online (Sandbox Code Playgroud)
参考本教程 http://schwarty.com/2015/12/22/angular2-relative-paths-for-templateurl-and-styleurls/
通过在运行时更改导入文件的路径(从src到dist)来解决我的问题,如下所示: -
moduleId: module.id.replace("/dist/", "/src/")
Run Code Online (Sandbox Code Playgroud)
通过这样做,您可以更改模块ID的路径目录.
感谢@Nicolai这篇精彩的评论
PS: - 发布答案可能对某人有所帮助
| 归档时间: |
|
| 查看次数: |
6649 次 |
| 最近记录: |