2016-05-04 124 views
4

當我使用templateUrl@Component我在瀏覽器控制檯中出現以下錯誤。無法加載app.html

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

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

[email protected]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<[email protected]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<[email protected]http://localhost:8080/common.js:10342:33 [616]/http://localhost:8080/vendor.js:6321:25 [616]/http://localhost:8080/vendor.js:6222:30 [email protected]http://localhost:8080/vendor.js:6440:27 ZoneTask/[email protected]http://localhost:8080/vendor.js:6392:23

ARH項目:

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

凡位於你的'app.html'文件?你能提供你的項目組織嗎? –

回答

1

根據你的錯誤,似乎路徑在templateUrl屬性模板是不正確的。

請注意,此類路徑相對於styleUrltemplateUrl屬性的項目根。

我認爲,你可以嘗試這樣的事情:

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

看到這個問題的更多細節:

+0

我嘗試寫如templateUrl:「app/app.html」和templateUrl:「./app/app.html」,但有這個問題 –

+0

您的模板文件位於項目的啓動文件夾位於何處? –

+0

app.ts它是引導文件。這是書ng2的例子。所有示例都不使用templateUrl。我不知道爲什麼會發生。 –