import { PLATFORM_ID } from '
@angular/core';
import { isPlatformBrowser, isPlatformServer } from '
@angular/common';
constructor(
@Inject(PLATFORM_ID) private platformId: Object) { ... }
ngOnInit() {
if (isPlatformBrowser(this.platformId)) {
// Client only code.
...
}
if (isPlatformServer(this.platformId)) {
// Server only code.
...
}
}