2016-11-21 12 views
0

templateタグにコードを埋め込んでいますが、コードは正常に動作しており、コンテンツを表示しています。Angular2 templateUrlで機能しません

コンテンツをtemplateUrlに移動すると、特定のページが見つからないことがコンソールに表示されます。

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

@Component({ 
    selector: 'home', 
    templateUrl: 'home.component.html' 
}) 

export class HomeComponent{ 

} 

tsconfig.js

{ 
"compilerOptions": { 
"target": "es5", 
"module": "commonjs", 
"moduleResolution": "node", 
"sourceMap": true, 
"emitDecoratorMetadata": true, 
"experimentalDecorators": true, 
"removeComments": false, 
"noImplicitAny": false 
} 
} 

404

home.component.tsはどうすればこの問題を克服するだろうか?

+0

Plunkerで再現できますか? –

+0

また、https://angular.io/docs/ts/latest/cookbook/component-relative-paths.htmlをチェックしてください。 – ranakrunal9

+0

'@ Component'にあなたが持っているものを投稿できますか? – brians69

答えて

0

commonjsモジュールが@ComponentディレクティブのmoduleId属性を必要とするように私のモジュールをcommonjsとして構成したので、module.idを@Componentディレクティブに追加することで、この問題を克服しました。我々は

は、コンポーネントファイルへの相対URLを使用するcommonjsモジュールを必要とする理由

は、あなたのプロジェクトがcommonjsモジュール(「モジュール」設定:「commonjs」のTSconfigでの)でなければならない、とあなたはmodule.idを含める必要があなたのコンポーネントデコレータで:[1]

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

@Component({ 
    moduleId: module.id, 
    selector: 'home', 
    templateUrl: 'home.component.html' 
}) 

export class HomeComponent{ 

} 

関連する問題