Comments (1)
Hey
From the universal chapter of the official Angular documentation: https://angular.io/guide/universal#working-around-the-browser-apis:
Because a Universal platform-server app doesn't execute in the browser, you may have to work around some of the browser APIs and capabilities that are missing on the server.
You won't be able reference browser-only native objects such as window, document, navigator or location. If you don't need them on the server-rendered page, side-step them with conditional logic.
Alternatively, look for an injectable Angular abstraction over the object you need such as Location or Document; it may substitute adequately for the specific API that you're calling. If Angular doesn't provide it, you may be able to write your own abstraction that delegates to the browser API while in the browser and to a satisfactory alternative implementation while on the server.
Without mouse or keyboard events, a universal app can't rely on a user clicking a button to show a component. A universal app should determine what to render based solely on the incoming client request. This is a good argument for making the app routeable.
Because the user of a server-rendered page can't do much more than click links, you should swap in the real client app as quickly as possible for a proper interactive experience.
So more or less you or a third party (like for example jQuery etc.) are accessing the window
object that doesn't exist on the server side. What you can do:
- In case it is your code, do a check and don't execute it. There is a way to detect if your code is running in the browser or on the server side: https://stackoverflow.com/questions/46099644/how-to-check-for-isbrowser-in-angular-4
- In case it is your code, write an abstraction that can be injected via dependency injection and that doesn't rely on the
window
object - In case of a third party library: Tricky....try to opt it out on the server side or search for an alternative that doesn't rely on
window
In case you aren't accessing window
by yourself, search for it in the server bundle and maybe you'll find out to with third party library it does belong?
from angularj-universal.
Related Issues (20)
- Cyrillic symbols with server side rendering HOT 3
- Question: AngularJ-Universal limitations HOT 1
- Release 0.0.2 HOT 2
- feature request: Add Lazy Loading module support HOT 2
- bug: Please delete temp files HOT 2
- Once the project is imported, how can I run it? HOT 3
- No provider for InjectionToken MODULE_MAP! with lazy loading HOT 3
- Getting a login page HOT 1
- Question: How to use parameterized routes and wildcard routes HOT 10
- Does graalvm help us? HOT 5
- Implement an upcomming TCP/gRPC renderer in Angular Universal HOT 1
- How to use Angular Universal with Spring Backend HOT 4
- How to use this library with angular 6 HOT 1
- Rendering takes too long HOT 6
- Getting the Request server side HOT 10
- Segmentation fault when running angularj in docker container HOT 3
- LazyModule using Socket engine HOT 2
- angular 8 not working HOT 6
- This is still alive HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from angularj-universal.