Is it possible to import a module based on condition? Specificly import external module only if angular 2 universal app being rendered in browser but not in server.
This question is relevant to some PrimeNG modules that depend on browser features and can be rendered only in browser. It would be great to omit them at server rendering cause calendars and other components are not really important for SEO.
Currently I can render Calendar component if turn off server rendering. But server produces an error 'ReferenceError: Event is not defined' in button.js when I include this code below in my app.module.ts and turn on server rendering.
import { CalendarModule } from 'primeng/components/calendar/calendar';
@NgModule({
...
imports: [
...,
CalendarModule
]
})
There is a isBrowser condition provided by angular.
import { isBrowser } from 'angular2-universal';
But I don't know how to use it for conditional imports. Is there really a way to do it for modules?