Solvedflex layout Using flex-layout with Angular Universal
✔️Accepted Answer
With the yesterday's 2.0.0-beta-4 release of angular/material2
, one of the highlights of which was improved Angular Universal support via PR 4251, I'm surprised angular/flex-layout
didn't have similar changes. I'd think they go hand in hand.
Other Answers:
I'm using beta.9 and I have the error
ReferenceError: document is not defined
Once PR #342 has been merged we will submit a revised PR for Angular Universal support.
When working with this you should focus on angular4 support instead of angular/universal given that 4 has universal built into @angular/platform-browser and @angular/platform-server.
@ThomasBurleson when working with document for universal you want to manipulate the renderer instead of document for rendering updates like your doing on https://github.com/angular/flex-layout/blob/master/src/lib/flexbox/api/base.ts#L138. If you have direct need for getDOM() you'll want to check for getDom() first and if it exists then isBrowser is true else your in node and probably won't be able to directly make that call.
Side note; a quick search through the current master is showing that you don't have any glaring issues with universal support so it should be pretty close to ready as is.
Both getDOM()
and the renderer will work fine on @angular/platform-server
- it's direct DOM access that needs to be avoided.
From my limited knowledge of Node, I gather that anything referencing
Document
orWindow
will throw a server-side error.That said, I'd like to incorporate flex-layout into my Angular Universal app. Is that possible? My initial attempt (simply following the readme) throws the following error: