且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

服务器端渲染Angular 4/5问题

更新时间:2023-11-27 21:56:34

这已经很晚了,但也许会对您或将来的某个人有所帮助. 使用Angular Universal时会发生这种情况,这是因为服务器端渲染没有窗口",只有浏览器有.

This is very late but maybe it will help you or someone in the future. This happens when using Angular Universal, its because the server side rendering doesnt have a 'window' to use, only the browser does.

因此,执行此代码时,服务器无法找到不存在的窗口.您可以通过删除Hammerjs来解决此问题(这不是必不可少的,只是增加了材质2和类似UI的生活质量)

So when this code is executed the server fails to find the non-existent window. You can fix this by either removing hammerjs (it isnt essential, just adds quality of life to material 2 and similar UI)

或者您可以在这里尝试此修复程序: https://github.com/angular/universal/issues/830

Or you can try this fix here: https://github.com/angular/universal/issues/830

其中涉及在server.ts代码中定义窗口,以便它在运行时可以正常工作.

Which involves defining the window in your server.ts code so when it runs it works correctly.