2016-10-29 2 views
0

새로운 앵글 2를 만들려고하는데 구성 요소 템플릿이 던지는 문제가 있습니다. 404 오류와 나는 내 인생에 대한 이유를 알아낼 수 없습니다.Angular 2 + mvc core : 리소스를로드하지 못했습니다 : 서버가 404 상태로 응답했습니다 (찾을 수 없음)

구성 요소를 구성하고 템플릿을 지정할 수 있지만 현재 탈출중인 이유로 콘솔에서 .js 파일로 참조되는 템플릿을 계속 볼 수 있습니다. 나는 다음과 같은 오류를 참조 예를 들어

:

Error: (SystemJS) XHR error (404 Not Found) loading http://localhost:5000/app/app.html.js [email protected]http://localhost:5000/node_modules/zone.js/dist/zone.js:698:34 [email protected]http://localhost:5000/node_modules/zone.js/dist/zone.js:265:40 [email protected]http://localhost:5000/node_modules/zone.js/dist/zone.js:154:57 [email protected]http://localhost:5000/node_modules/zone.js/dist/zone.js:335:40 Error loading http://localhost:5000/app/app.html.js as "app/app.html" from http://localhost:5000/app/app.component.js

지금 나는 내가 app.html.js이없는 알지만, 왜 각 파일을로드하려고 알아낼 수 없습니다에게 그 존재하지 않습니다. 그 이상으로 혼란에 빠지면 템플릿을 app.html로 명시 적으로 설정하고 있다는 것을 알게됩니다.

import { Component } from "@angular/core"; 
import { Router } from "@angular/router"; 

const template = require("./app/app.html"); 

@Component({ 
    selector: "alerts", 
    template: template 
}) 

export class AppComponent { 
    constructor(public router: Router) {} 
} 

어떤 도움을 주시면 감사하겠습니다.

편집 그냥 외부 템플릿을 제거하여 나는 또한 그것을 단순화 한 구성 요소를 배제하고 구성 요소에 직접 템플릿 마크 업을 넣고 난 여전히 같은 결과를 얻을 수, 파일을 찾고 각도가 이잖아하지도 않습니다 참조 또는 기존 :

import { Component } from "@angular/core"; 
import { Router } from "@angular/router"; 

@Component({ 
    selector: "alerts", 
    template: `<alerts></alerts>` 
}) 

export class AppComponent { 
    constructor(public router: Router) {} 
} 

답변

0

moduleId:module.id,을 사용하는 것이 할 수있는 더 쉬운 방법을 따라서

@Component({ 
    moduleId:module.id, // this makes the .html relative to the folder you are in 
    selector: "alerts", 
    templateUrl: app.html 
}) 
필요가 필요하지
관련 문제