【问题标题】:How do I resolve type errors using angular2 and aspnet core?如何使用 angular 和 asp net core 解决类型错误?
【发布时间】:2017-10-30 09:56:30
【问题描述】:

我使用 dotnet cli 工具创建了一个新的 Angular 应用程序,一切看起来都很好。

C:/..myprojectlocation> dotnet new angular

这将使用 Angular 应用程序创建一个新的文件夹和文件结构。在此之后,我转到 home.component 并从 angular 导入 AfterViewInit 事件。

import { Component, AfterViewInit } from '@angular/core';

同样,我添加了事件处理程序:

ngAfterViewInit(): void {
    const inputs: NodeListOf<HTMLInputElement> =
                        document.getElementsByTagName("input");
}

当我构建我的项目时,它超出了但是当我刷新我的页面时,我在运行时收到以下错误。

An unhandled exception occurred while processing the request.

Exception: Call to Node module failed with error: Error: Uncaught (in 
   promise): ReferenceError: document is not defined
   ReferenceError: document is not defined

这感觉像是一段相当微不足道的代码,但是当我尝试与其他模块交互时,我一遍又一遍地遇到类似的问题。我可以在 google 上找到看似相似的问题,但似乎没有太多的方向或如何解决它们。

可能与 HotModuleReplacement、Weback2、angular/universal 或 typescript 版本有关。但是,老实说,我没有太多线索,所以在我理解这个问题之前,我被困住了。

【问题讨论】:

    标签: angular asp.net-core typeerror webpack-2


    【解决方案1】:

    你的 html 中有类似的东西吗?

    <app asp-prerender-module="xxxxxxxxx">Loading...</app>
    

    尝试更改为

    <app asp-ng2-prerender-module="xxxxxxx">Loading...</app>
    

    【讨论】:

    • 有人请这个人喝一杯!所以,到目前为止,这看起来已经解决了我的痛苦。真希望我早点找到这个。
    猜你喜欢
    • 1970-01-01
    • 2021-05-31
    • 1970-01-01
    • 2022-08-03
    • 2020-12-11
    • 2018-12-20
    • 2017-08-23
    • 1970-01-01
    • 2021-07-21
    相关资源
    最近更新 更多