据我所知,Angular 2组件中的所有templateUrl和styleUrl路径都是从index.html
解析的。
我想分开我的开发和运行文件夹,因此我的.html文件包含我的.ts模块,路由器,组件等在dev
文件夹中。并将.js编译为兄弟app
文件夹,其中应该从中启动角度。
目录结构如下:
top directory
|
*-- app (compiled .js here, index.html here)
|
*-- dev (.ts here, .component.html files here)
问题是,当dev
位于app文件夹中时,我无法访问index.html
文件夹中的.component.html文件。我已尝试从app文件夹中进入绝对路径,然后进入兄弟文件夹,但这似乎无法正常工作。
@Component({
templateUrl: 'app/../dev/path/path.component.html'
...
)}
上述情况中的错误是在localhost:3000/dev/path/path.component.html
将.component.html结构和文件复制到/ app工作但很麻烦。
是否可以将templateUrl(styleUrl)位置设置为上游父级或兄弟级index.html
的位置?
答案 0 :(得分:1)
没有通过路径解决这个问题。解决方案是将htmls直接编译为Angular2组件或将htmls复制到app
文件夹