【发布时间】:2018-03-02 14:18:35
【问题描述】:
我正在使用带有 angular 4 和 webpack 配置的 dot net core。
当我尝试在组件或服务中获取窗口或文档时,我收到此错误:
ReferenceError: 文档未定义
ReferenceError: 未定义窗口
这是我得到的错误:
Microsoft.AspNetCore.NodeServices[0]
ERROR { ReferenceError: window is not defined
at _window (C:\gitRepose\AngularCore\FM\FMWebApp\FootballWebApp\ClientApp\dist\main-server.js:30801:12)
Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware[0]
An unhandled exception has occurred: window is not defined
ReferenceError: window is not defined
at _window (C:\gitRepose\AngularCore\FM\FMWebApp\FootballWebApp\ClientApp\dist\main-server.js:30801:12)
我还是 webpack 的新手,有谁知道我该如何解决这个问题? 当窗口调整大小时,我需要窗口来处理。
编辑...
我设法通过从 index.cshtml 中删除预渲染来解决这个问题
我从这里改变了它:
<app asp-prerender-module="ClientApp/dist/main-server">Loading...</app>
到这里:
<app>Loading...</app>
但现在显然不会在服务器端进行预渲染:/ 因此它会减慢应用程序的启动时间,有什么想法可以在不丢失服务器端预渲染的情况下解决这个问题吗?
【问题讨论】:
-
您是否使用Microsoft ASP.NET Core SPA Templates 生成您的项目?
-
是的,我用过它们,为什么?
标签: javascript angular webpack .net-core