我的ASP.NET Core Angular 2网络应用程序出现了间歇性异常:
Exception: Call to Node module failed with error: Error: This method is not implemented in Parse5DomAdapter: Parse5DomAdapter#getCookie
at _notImplemented (D:\Projects\MyProject\MyProject\node_modules\angular2-platform-node\parse5-adapter.js:22:12)
at Parse5DomAdapter.getCookie (D:\Projects\MyProject\MyProject\node_modules\angular2-platform-node\parse5-adapter.js:641:15)
at CookieXSRFStrategy.configureRequest (D:\Projects\MyProject\MyProject\node_modules\@angular\http\bundles\http.umd.js:1597:92)
at XHRBackend.createConnection (D:\Projects\MyProject\MyProject\node_modules\@angular\http\bundles\http.umd.js:1637:32)
at httpRequest (D:\Projects\MyProject\MyProject\node_modules\@angular\http\bundles\http.umd.js:1975:24)
at Http.get (D:\Projects\MyProject\MyProject\node_modules\@angular\http\bundles\http.umd.js:2086:20)
at ApiService.getChatMessages (D:\Projects\MyProject\MyProject\ClientApp\dist\main-server.js:557:20)
at ChatPageComponent.ngOnInit (D:\Projects\MyProject\MyProject\ClientApp\dist\main-server.js:513:23)
at AppView._View_ChatPageComponent_Host0.detectChangesInternal (ChatPageComponent_Host.ngfactory.js:30:86)
at AppView.detectChanges (D:\Projects\MyProject\MyProject\node_modules\@angular\core\bundles\core.umd.js:9566:18)
MoveNext
我认为它与MVC视图有关,因为错误显示:
MoveNext in Index.cshtml
1.@{
2. ViewData["Title"] = "Home Page";
3.}
4.
5.<app asp-prerender-module="ClientApp/dist/main-server">Loading...</app>
6.
7.<script src="~/dist/vendor.js" asp-append-version="true"></script>
8.@section scripts {
我的index.cshtml中的代码。
似乎在启动项目后很早就发生了。这一切都可以正常工作,或者在执行任何导航时加载主页后会抛出错误。
我可以强制它产生错误。我有4个导航目的地:
http://localhost:49954/home
http://localhost:49954/counter
http://localhost:49954/fetch-data
http://localhost:49954/chat-page
这些都是从Visual Studio Angular 2模板设置的。如果我回家,一切都很好,如果它有机会加载一段时间我可以导航到其他页面。但是,如果我输入任何其他页面的URL,则每次都会产生此错误。
编辑:另外,有趣的是,它与http://localhost:49954/counter
产生了略微不同的错误。在我的计数器页面中,我使用了Angular Material Design组件:
<div class="mine">
<h2>
Counter Test
</h2>
<p>This is a simple example of an Angular 2 component.</p>
<p>Current count:<strong>{{ currentCount }}</strong></p>
<button md-raised-button (click)="incrementCounter()">Increment</button>
</div>
而不是上述错误,它是一个类似的调用节点模块失败错误,但在材料设计中:
Exception: Call to Node module failed with error: Error: Uncaught (in promise): ReferenceError: document is not defined
ReferenceError: document is not defined
at new RippleRenderer (D:\Projects\MyProject\MyProject\node_modules\@angular\material\material.umd.js:193:31)
答案 0 :(得分:25)
这对我有用。变化:
<app asp-prerender-module="ClientApp/dist/main-server">Loading...</app>
到
<app asp-ng2-prerender-module="ClientApp/dist/main-server">Loading...</app>
index.html中的
答案 1 :(得分:15)
编辑:几个月后,这已经过时了,Jimmy发布了更好的解决方案。所以移动&#34;正确&#34;他回答的标记。
预渲染似乎是一个问题,因为Angular 2 Material与Angular Universal不兼容。
我改变了:
<app asp-prerender-module="ClientApp/dist/main-server">Loading...</app>
为:
<app class="container" style="display: block;">Loading...</app>
在index.cshtml中它现在运行正常(使用&#34;正在加载......&#34;直到完全加载)。
答案 2 :(得分:3)
要更清楚一点,请编辑Views / Home / index.html并更改以下行:
<app asp-prerender-module="ClientApp/dist/main-server">Loading...</app>
以下
<app asp-ng2-prerender-module="ClientApp/dist/main-server">Loading...</app>