为什么我们在angular2中使用moduleId:module.id

问题描述:

为什么在使用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

组件的相关资产,例如@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'] 
})