Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET Core Angular Template: app.module.client vs. app.module.server

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".

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.

screenshot of <code>app.module.client.ts</code> and <code>app.module.server.ts</code>

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:

full ASP.NET Core Angular template

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.

Here is what the two files look like:

<code>app.module.client.ts</code> and <code>app.module.server.ts</code> code side-by-side

like image 535
NetherGranite Avatar asked Jun 14 '17 17:06

NetherGranite


1 Answers

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.

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.

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.

like image 91
Peter Harrison Avatar answered Oct 07 '22 17:10

Peter Harrison