javascript - 无法加载 app.html

标签 javascript node.js angular

当我在 @Component 中使用 templateUrl 时,我在浏览器控制台中收到以下错误。

@Component({
  selector: 'http-app',
  directives: [
  ],
  templateUrl: "app.html",
})
class HttpApp {
}

Error: Uncaught (in promise): Failed to load app.html

resolvePromise@http://localhost:8080/vendor.js:6504:33 makeResolver/<@http://localhost:8080/vendor.js:6481:15 ApplicationRef_http://localhost:8080/common.js:9943:26 [616]/http://localhost:8080/vendor.js:6289:21 NgZoneImpl/this.inner<.onInvoke@http://localhost:8080/common.js:10351:33 [616]/http://localhost:8080/vendor.js:6288:21 [616]/http://localhost:8080/vendor.js:6182:26 scheduleResolveOrReject/<@http://localhost:8080/vendor.js:6537:54 [616]/http://localhost:8080/vendor.js:6322:25 NgZoneImpl/this.inner<.onInvokeTask@http://localhost:8080/common.js:10342:33 [616]/http://localhost:8080/vendor.js:6321:25 [616]/http://localhost:8080/vendor.js:6222:30 drainMicroTaskQueue@http://localhost:8080/vendor.js:6440:27 ZoneTask/this.invoke@http://localhost:8080/vendor.js:6392:23

项目架构:

Test
-app
--css
--img
--ts
---components
----login
-----login.ts
-----login.html
----services
---app.ts
---app.html
---vendor.ts
--index.html

最佳答案

根据您的错误,您的模板在 templateUrl 属性中的路径似乎不正确。

请注意,此类路径相对于 styleUrltemplateUrl 属性的项目根目录。

我认为你可以尝试这样的事情:

@Component({
  selector: 'http-app',
  directives: [
  ],
  templateUrl: "app/app.html",
})
class HttpApp {
}

有关详细信息,请参阅此问题:

关于javascript - 无法加载 app.html,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37034709/

相关文章:

javascript - 如何在用户执行 "scroll"或 "touch"或 "Click"事件时关闭移动 View 中的侧边栏

javascript - 多人/访客与 Ruby on Rails 的交互?

node.js - 两个http请求能走到一起吗?如果可以,nodeJS 服务器如何处理它?

node.js - Nest 无法解析 ... 的依赖项。请确保索引 [0] 处的参数 .. 在

angular 4 httpGet withCredentials 和 header 冲突

javascript - Angular 4 Bootstrap 菜单在页面交换时保持打开状态

javascript - 如何在一个 JS 函数中编写多个函数

javascript - 使用 Diffie-Hellman key 交换和 AES 通过 HTTP 进行客户端加密

jquery - Angular 中的动画

javascript - Handlebars/Ember.Checkbox - 2 个绑定(bind)的复选框,一个勾选为 false