ASP.NET Core Angular模板:app.module.client与app.module.server [英] ASP.NET Core Angular Template: app.module.client vs. app.module.server

查看:146
本文介绍了ASP.NET Core Angular模板:app.module.client与app.module.server的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Microsoft提供了一个出色的模板,用于在ASP.NET Core中开发Angular(不是AngularJS),如其文章"

Microsoft provides a fantastic template for developing Angular (not AngularJS) in ASP.NET Core as outlined in their article "Building Single Page Applications on ASP.NET Core with JavaScriptServices".

虽然非常简单,但是模板的一部分让我措手不及:不仅有一个app.module.ts文件,而且还有一个app.module.client.tsapp.module.server.ts.

While it's very straightforward, there is one portion of the template that caught me off guard: instead of there simply being an app.module.ts file, there are both an app.module.client.ts and an app.module.server.ts.

我在网络上找不到任何能解释这一点的内容.有谁知道为什么应用模块有两个单独的文件,它们的用途是什么,如何使用等?

I failed to find anything that explains this on the web. Does anyone have any idea why there are these two separate files for the app module, what their specific uses are, how to use them, etc.?

如果有帮助,则完整的模板如下所示:

If it helps at all, here is what the full template looks like:

我应该注意,ClientApp/app/modelsClientApp/app/services是我出于个人目的添加的两个文件夹;它们不是模板的一部分.另外,app.module.shared.ts实际上非常简单明了,只是避免了必须编写两次代码,所以不必担心.

I should note that ClientApp/app/models and ClientApp/app/services are two folders I added for my own purposes; they are not part of the template. Also, app.module.shared.ts is actually very straight-forward and just prevents having to write some code twice, so don't worry about it.

这是两个文件的样子:

推荐答案

让我开始声明,我对这句话的准确性不是100%,但是既然没有其他人回答,我就给它一枪.

Let me start by prefacing that I'm not 100% on the accuracy of this statement, but since nobody else seems to have answered, I'll give it a shot.

带有Angular 2的Microsoft SPA利用Angular Universal进行AOT渲染.现在已升级为使用Angular 4,而不再使用Angular Universal.我的想法是,它将app.module.ts分解为客户端和服务器文件以帮助AOT渲染.

Microsoft SPA with Angular 2 utilized Angular Universal to do the AOT rendering. It has now been upgraded to use Angular 4, which doesn't use Angular Universal. My thought is that it instead broke up the app.module.ts into a client and server file to help with AOT rendering.

app.module.shared.ts文件实际上只是app.module.client.ts和app.module.server.ts使用的全局常量.由于在发布过程中所有内容都呈现为几个js文件,因此它们将app.module文件分开并没有关系.

The app.module.shared.ts file is actually just a global constant that is used by app.module.client.ts and app.module.server.ts. Because it all gets rendered into a couple js files during publication, it doesn't really matter that they split up the app.module file.

这篇关于ASP.NET Core Angular模板:app.module.client与app.module.server的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆