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
Now that the Library is setup, you have a few great helpers to make Angular Universal a bit simpler and easier to work with!
51
+
52
+
## PlatformService
53
+
54
+
Typically in Angular Universal Applications you have sections of code that can only run in certain platforms (browser or server), with PlatformService you can simply add it in the constructor of any Component/Service within your application, and run code specific to that platform - without causing Errors in the _other_ platform.
// Run browser-specific code that would cause errors in the Server/Node platform!
64
+
// $('body').addClass('');
65
+
}
66
+
67
+
if (platformService.isServer) {
68
+
// Run Server/Node-specific code
69
+
}
70
+
}
71
+
}
72
+
73
+
```
74
+
75
+
## IsBrowser | IsService Directives
76
+
77
+
Equally important with Angular Universal is displaying only Components/UI that are _neccessary_ for the given platform. To improve performance, or to avoid Components all-together we can use `*isBrowser` or `*isServer` Directives to display/hide specific things given a platform.
78
+
79
+
Take as an example a Twitter Feed section that's connected to 3rd party Components/Libraries and API-calls. We don't need Universal to display these as there is no SEO benefit, and most likely they will slow down our Render time. In this case it's most beneficial to simply avoid it entirely during server-side rendering, and have _only_ the **Browser** display and render this Component!
0 commit comments