Unfortunately for server side rendering to work, your code should be isomorphic, if you need to run any browser specific code you will need to test which platform you are before run it, like this:

import { Component, PLATFORM_ID, Inject } from '@angular/core';
import { isPlatformBrowser, isPlatformServer } from '@angular/common';

@Component({
selector: 'app-postfeed',
templateUrl: './postfeed.component.html',
styleUrls: ['./postfeed.component.css']
})
export class PostfeedComponent implements OnInit {

constructor(@Inject(PLATFORM_ID) private platform: Object) { }

ngOnInit() {
if (isPlatformBrowser(this.platform)) {
// here you can run any browser specific code, like:
window.alert('This will run only in the browser!');
}
}
}

If you are using some UI library which uses the DOM directly, unfortunately you will not be able to use SSR with it.

I’d tried to use 2 separate modules and mock libraries, but it didn’t work for me.

If you are only using the animations module, you will need to import NoopAnimationsModule on the ServerAppModule.

    Éverton Roberto Auler

    Written by

    Developer/Entrepreneur