英文:
What is the usability of fields/ methods in an angular module?
问题
Angular模块的字段/方法等是否有可用性?如果有,那么它在什么情况下有用?
英文:
Is there any usability for fields/ methods etc. of an angular module?
If so – when is it useful?
答案1
得分: 1
你通常会在模块中找到 forRoot/forChild
方法,但除此之外,没有太多内容。
我个人喜欢进行模块范围的设置和配置:例如,使用 Angular Material,您可以提供自己的 SVG 图标以供使用。在这种情况下,我喜欢将我的图标提供到应用程序模块中。
通常,您还可以在模块中初始化状态管理,并执行所需的所有样板代码(例如从服务器获取一些静态数据等)。
最终,这更多地涉及到代码位置和个人偏好,但模块并不意味着包含代码,它们用于打包您想要重用的功能,并组织您的代码。
英文:
You would usually find forRoot/forChild
methods in modules, but other than that, not much.
What I personally like to do is make module-wide settings and configurations : for instance, with Angular Material, you can provide your own SVGs to be treated as icons. In that particular case, I like to provide my icons into the app module.
Another thing you can usually do in your modules is initiate your state management, and do all the boilerplate required for it (getting some static data on the server etc).
In the end, it's more about code location and your own personal preferences, but modules are not meant to hold code, they are here to package a feature that you want to reuse, and to organize your code.
答案2
得分: 0
以下是您要翻译的内容:
"我看到模块中方法最常见的用法是返回专用于该模块的提供程序列表。您可以在 Angular 代码库中找到许多这样的示例,例如在 BrowserModule
中:"
英文:
The most common usecase I see for methods in a module is returning a list of providers dedicated to that module.
You can find a lot of them in the angular code base.
For example in BrowserModule
:
static withServerTransition(params: {appId: string}): ModuleWithProviders<BrowserModule> {
return {
ngModule: BrowserModule,
providers: [
{provide: APP_ID, useValue: params.appId},
],
};
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论