When working with Angular Universal and doing Server Side Rendering, different dificulties always force us to check what platform we are running on and avoid executing certain parts of our code.
UniversalService
simplifies platform detection code and boostrapping:
Use the onXXX()
methods to condition execution of a section of your code to a specific platform.
TLDR
Why the service?Before @bespunky/angular-zen
, the way to check what platform the app is running on was to inject PLATFORM_ID
and pass it to the isPlatformXXX()
function:
I've always found this to be tedious to write and frustrating to read.
UniversalService
wraps the old syntax and provides a simpler and cleaner way.