gpt4 book ai didi

Angular - 组件中 module.id 的含义是什么?

转载 作者:太空狗 更新时间:2023-10-29 16:44:09 30 4
gpt4 key购买 nike

在 Angular 应用程序中,我看到 @Component 具有属性 moduleId。这是什么意思?

module.id 没有在任何地方定义时,应用程序仍然可以工作。怎么还能用?

@Component({
moduleId: module.id,
selector: 'ng-app',
templateUrl: 'app.component.html',
styleUrls: ['app.component.css'],
directives: [AppComponent]
});

最佳答案

Angular 的测试版(从 2-alpha.51 版本开始)支持组件的相关资源,例如 @Component 中的 templateUrlstyleUrls装饰器。

module.id使用 CommonJS 时有效。您无需担心它的工作原理。

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's post , 感谢 @Pradeep Jain

2016 年 9 月 16 日更新:

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 的含义是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37178192/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com