For instance React's componentWillMount():
This is the only lifecycle hook called on server rendering. Generally, we recommend using the
constructor()instead.
And in React's componentDidMount()
componentDidMount()is invoked immediately after a component is mounted. Initialization that requires DOM nodes should go here.
However I do not see anything in the Angular doc specifying which ones are executed on the server and which ones are executed on the browser (or both). Or should I assume that all of them are executed on both? If so, how do you do things that require the DOM (window, document, etc.)?
No, it doesn't. It runs the same hooks.
There's plenty of devices you can use to avoid contact with plain DOM, like HostBinding and HostListener decorators, Renderer and ElementRef classes. Remember that Angular 2 is a high-abstraction tool. It doesn't promotes access the DOM, although it is possible. Also, for server-side rendering, DI also comes to the rescue when there are different implementations for server and client.
Learn about Angular Universal to know more about server-side rendering at https://github.com/angular/universal.
If that doesn't answer your question, please place a more specific question.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With