2017-02-17 52 views
1

爲什麼在使用templateUrlAngular 2組件時需要使用moduleId:module.id爲什麼我們在angular2中使用moduleId:module.id

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

@Component({ 
    moduleId:module.id, 
    selector: 'my-app', 
    templateUrl:`app.component.html`, 
}) 

export class AppComponent { name = 'Angular 2 website'; } 
+0

'的moduleId:module.id'解決相對路徑的 – anshuVersatile

+4

可能的複製[Angular2 - 什麼是的含義module.id in component?](http://stackoverflow.com/questions/37178192/angular2-what-is-the-meanings-of-module-id-in-component) – jonrsharpe

回答

4

組件的相關資產,例如@Component裝飾器中的templateUrl和styleUrls。

moduleId用於解析樣式表和模板的相對路徑,如文檔中所述。

沒有模塊ID

@Component({ 
    selector: 'my-component', 
    templateUrl: 'app/components/my.component.html', 
    styleUrls: ['app/components/my.component.css'] 
}) 

隨着模塊ID

@Component({ 
    moduleId: module.id, 
    selector: 'my-component', 
    templateUrl: 'my.component.html', 
    styleUrls: ['my.component.css'] 
}) 
相關問題