如何使用angular2和aspnet core解决类型错误? [英] How do I resolve type errors using angular2 and aspnet core?

查看:38
本文介绍了如何使用angular2和aspnet core解决类型错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用dotnet cli工具创建了一个新的有角度的应用程序,一切看起来和工作都很好.

I used dotnet cli tool to create a new angular application and everything looks and works fine.

C:/..myprojectlocation> dotnet new angular

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

This creates a new folder and file structure with the angular application. After this, I go to the home.component and import AfterViewInit event from angular.

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

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

As well, I add the event handler:

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

构建项目时,该项目超出了限制,但是刷新页面时,在运行时出现以下错误.

When, I build my project it exceeds but when I refresh my page I get the following error at run-time.

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上找到看似相似的问题,但似乎并没有太大的方向或如何解决这些问题.

This feels like a fairly insignificant piece of code but I have encountered similar problems over and over as I try to interface with other modules. I can find seemingly similar issues on google none seem to have much direction to they are or how to fix them.

可能与HotModuleReplacement,Weback2,Angular/Universal或打字稿版本有关.但是,老实说,我没有太多线索,所以我被困住了,直到我理解了这个问题.

Could be related to HotModuleReplacement, Weback2, angular/universal, or typescript version. But, I honestly don't have many leads so I am stuck until I understand the issue.

推荐答案

您的html中是否有类似的东西?

Do you have something like this in your html?

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

尝试更改为

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

这篇关于如何使用angular2和aspnet core解决类型错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆