You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+222-2Lines changed: 222 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -88,13 +88,36 @@
88
88
89
89
# Getting Started?
90
90
91
-
**Make sure you have at least Node 4.x or higher installed!**
91
+
**Make sure you have at least Node 6.x or higher (w/ npm 3+) installed!**
92
+
93
+
### Visual Studio 2017
92
94
93
95
Make sure you have .NET Core 1.0+ installed and/or VS2017.
94
96
VS2017 will automatically install all the neccessary npm & .NET dependencies when you open the project.
95
97
96
98
Simply push F5 to start debugging !
97
99
100
+
### Visual Studio Code
101
+
102
+
> Note: Make sure you have the C# extension & .NET Core Debugger installed.
103
+
104
+
The project comes with the configured Launch.json files to let you just push F5 to start the project.
105
+
106
+
```bash
107
+
# cd into the directory you cloned the project into
108
+
npm install && dotnet restore
109
+
# or yarn install
110
+
```
111
+
112
+
If you're running the project from command line with `dotnet run` make sure you set your environment variables to Development (otherwise things like HMR won't work).
> Just remember, you'll usually only need to worry about `app.module.ts`, as that's where you'll be adding most
231
+
of your applications new aspects!
232
+
233
+
234
+
### /Server/ - Our REST API (WebApi) - MVC Controller
235
+
236
+
> As we pointed out, these are here for simplicities sake, and realistically you may want separate projects
237
+
for all your microservices / REST API projects / etc.
238
+
239
+
We're utilizing MVC within this application, but we only need & have ONE Controller, named `HomeController`. This is where our entire
240
+
Angular application gets serialized into a String, sent to the Browser, along with all the assets it needs to then bootstrap on the client-side, and become a full-blown SPA afterwards.
241
+
242
+
---
243
+
244
+
The short-version is that we invoke that Node process, passing in our Request object & invoke the `boot-server` file, and we get back a nice object that we pass into .NETs `ViewData` object, and sprinkle through out our `Views/Shared/_Layout.cshtml` and `/Views/Home/index.cshtml` files!
245
+
246
+
A more detailed explanation can be found here: [TODO-add-link * You can read a more detailed explanation here](#)
Take a look at the `_Layout.cshtml` file for example, notice how we let .NET handle and inject all our SEO magic (that we extracted from Angular itself) !
264
+
265
+
```html
266
+
<!DOCTYPE html>
267
+
<html>
268
+
<head>
269
+
<basehref="/" />
270
+
<!-- Title will be the one you set in your Angular application -->
### What happens after the App gets server rendered?
298
+
299
+
Well now, your Client-side Angular will take over, and you'll have a fully functioning SPA. (But we gained all these great SEO benefits of being server-rendered) !
### How can I disable Universal / SSR (Server-side rendering)?
353
+
354
+
Simply comment out the logic within HomeController, and replace `@Html.Raw(ViewData["SpaHtml"])` with just your applications root
355
+
AppComponent tag ("app" in our case): `<app></app>`.
356
+
357
+
> You could also remove any `ifPlatformBrowser/etc` logic, and delete the boot-server, browser-app.module & server-app.module files, just make sure your `boot-client` file points to `app.module`.
358
+
359
+
### How do I have code run only in the Browser?
360
+
361
+
Check the [Universal Gotchas](#universal-gotchas) on how to use `isPlatformBrowser()`.
362
+
363
+
### How do I Material2 with this repo?
364
+
365
+
You'll either want to remove SSR for now, or wait as support should be coming to handle Universal/platform-server rendering.
366
+
367
+
### How can I use jQuery and/or some jQuery plugins with Angular Universal?
368
+
369
+
> Note: If at all possible, try to avoid using jQuery or libraries dependent on it, as there are
370
+
better, more abstract ways of dealing with the DOM in Angular (2+) such as using the Renderer, etc.
371
+
372
+
Yes, of course but there are a few things you need to setup before doing this. First, make sure jQuery
373
+
is included in webpack vendor file, and that you have a webpack Plugin setup for it. `new webpack.ProvidePlugin({ $: 'jquery', jQuery: 'jquery' })`
374
+
375
+
Now, make sure any "plugins" etc that you have, are only included in your `boot-client.ts` file. (ie: `import 'slick-carousel';`)
376
+
In a Component you want to use jQuery, make sure to import it near the top like so:
377
+
378
+
```typescript
379
+
import * as $ from 'jquery';
380
+
```
381
+
382
+
**Always make sure to wrap anything jQuery oriented in Angular's `isPlatformBrowser()` conditional!**
383
+
169
384
----
170
385
171
386
# Special Thanks
@@ -174,6 +389,7 @@ Many thanks go out to Steve Sanderson ([@SteveSandersonMS](https://github.com/St
0 commit comments