【问题标题】:Getting ReferenceError: HTMLInputElement is not defined with Angular 4 Universal获取 ReferenceError:HTMLInputElement 未使用 Angular 4 Universal 定义
【发布时间】:2018-01-02 11:52:05
【问题描述】:

我有一个在 CDN 上运行的 Angular 4 上运行的应用程序。我正在尝试将其移植到 Angular Universal,因为 Google 爬虫在爬取我的网站时表现不佳。尝试运行 Node 服务器脚本时遇到以下错误,

@ViewChild('text') text: HTMLInputElement;

ReferenceError: HTMLInputElement 未定义

我认为这与 Node 引擎不知道 HTMLInputElement 是什么有关,因为它是浏览器原生的。无论如何我可以导入它或添加一个包以便 Node 识别它吗?

非常感谢。

【问题讨论】:

  • 我对此不太了解,但是如果您尝试将文本变量的类型设置为any 并使用text.nativeElement 调用它,它会起作用吗?

标签: node.js angular universal


【解决方案1】:

可能为时已晚,但只是为了回答这个问题,您应该使用

@ViewChild('text') text: ElementRef;

import { ElementRef } from '@angular/core';

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-12-29
    • 1970-01-01
    • 1970-01-01
    • 2020-11-12
    • 2018-09-25
    • 2020-08-05
    • 1970-01-01
    • 2020-02-15
    相关资源
    最近更新 更多