【问题标题】:Angular 2 using templateUrl styleUrl locations upstream from index.htmlAngular 2 使用 index.html 上游的 templateUrl styleUrl 位置
【发布时间】:2017-01-22 02:05:19
【问题描述】:

据我了解,Angular 2 组件中的所有 templateUrl 和 styleUrl 路径都是从 index.html 解析的。

但是,我想将我的开发和运行文件夹分开,因此将我的 .html 文件与我的 .ts 模块、路由器、组件等放在 dev 文件夹中。并已将 .js 编译到应从其中启动 Angular 的兄弟 app 文件夹。

目录结构如下:

top directory
|
*-- app (compiled .js here, index.html here)
|
*-- dev (.ts here, .component.html files here)

问题是我无法访问 dev 文件夹中的 .component.html 文件,而 index.html 位于 app 文件夹中。我已经尝试从 app 文件夹进行绝对路径向上并进入同级文件夹,但这似乎不起作用。

@Component({
    templateUrl: 'app/../dev/path/path.component.html'
    ...
)}

上述情况的错误是 404 not found on the .html file from localhost:3000/dev/path/path.component.html

将 .component.html 结构和文件复制到 /app 可以,但很麻烦。

是否可以将 templateUrl (styleUrl) 位置上游设置为 index.html 所在的父级或兄弟级?

【问题讨论】:

    标签: angular


    【解决方案1】:

    没有通过路径解决这个问题。解决方案是将 html 直接编译到 Angular2 组件中,或者将 html 复制到 app 文件夹中

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-07-25
      • 2017-06-14
      • 2017-10-28
      • 2016-10-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多