Angular - 组件中 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 的帖子
Source from Justin Schwartzenberger's post, thanks to @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
这篇关于Angular - 组件中 module.id 的含义是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!