角度-组件中module.id的含义是什么? [英] Angular - What is the meanings of module.id in component?
问题描述
在Angular应用中,我已经看到@Component
具有属性moduleId
.这是什么意思?
In an Angular app, I have seen that @Component
has property moduleId
. What does it mean?
并且在任何地方都未定义module.id
时,该应用程序仍然可以运行.仍然如何工作?
And when module.id
is not defined anywhere, the app still works. How can it still work?
@Component({
moduleId: module.id,
selector: 'ng-app',
templateUrl: 'app.component.html',
styleUrls: ['app.component.css'],
directives: [AppComponent]
});
推荐答案
Angular的beta版本(自vesion 2-alpha.51起)支持组件的相对资产,例如 templateUrl 和 @Component
装饰器中的styleUrls .
The beta release of Angular (since vesion 2-alpha.51) supports relative assets for components, like templateUrl and styleUrls in the @Component
decorator.
module.id
在使用CommonJS时有效.您无需担心其工作原理.
module.id
works when using CommonJS. You don't need to worry about how it works.
记住:在@Component装饰器中设置moduleId:module.id为 这里的关键.如果没有,Angular 2将会寻找 在根目录下保存文件.
Remember: setting moduleId: module.id in the @Component decorator is the key here. If you don't have that then Angular 2 will be looking for your files at the root level.
来自 Justin Schwartzenberger的帖子,这要感谢 @Pradeep Jain
2016年9月16日更新:
如果您使用 webpack 进行捆绑,则不需要 装饰器中的
module.id
. Webpack插件自动处理(添加)module.id
在最终捆绑包中
If you are using webpack for bundling then you don't need
module.id
in decorator. Webpack plugins auto handle (add it)module.id
in final bundle
这篇关于角度-组件中module.id的含义是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!