angular - 读取类型的参数:typeof elementref 不可分配给类型属性静态的参数类型中缺少
问题描述
我在 ag-angular-grid 中创建了自定义日期过滤器。这是日期过滤器组件:
import { Component, ElementRef, ViewChild } from '@angular/core';
@Component({
selector: 'app-loading-overlay',
template: `
<div #flatpickrEl class="ag-input-wrapper custom-date-filter" role="presentation">
<input type='text' data-input />
<a class='input-button' title='clear' data-clear>
<i class='fa fa-times'></i>
</a>
</div>
`,
})
export class CustomDateFilter {
@ViewChild("flatpickrEl", { read: typeof ElementRef }) flatpickrEl: ElementRef;
.....
}
错误在这个地方:{ read: typeof ElementRef }
错误是:
A wrapper around a native element inside a View.
An ElementRef is backed by a render-specific element. In browser, this is usually a DOM element.
argument of type {read: 'string' | 'number' | 'boolean' | 'symbol' | 'undefined' | 'object' | 'function' } is not assignable to parameter of type { read?: any static: boolean; } Property 'static' is missing in type {read: 'string' | 'number' | 'boolean' | 'symbol' | 'undefined' | 'object' | 'function' }
解决方案
从 Angular 8 开始,您需要static
在选项中提供属性:
@ViewChild("flatpickrEl", { read: typeof ElementRef, static: true | false }) flatpickrEl: ElementRef;
推荐阅读
- flutter - 发现很难导航到另一个页面
- php - 如何在 mysql JSON 中搜索某个属性?
- openssl - Kerberos PKINIT - 未找到匹配条目 preauth (pkinit) 验证失败:证书不匹配
- c# - 获取 netsh 显示的代理
- microsoft-teams - Microsoft Teams Graph 和 OnlineMeetings
- javascript - 如何按索引禁用输入?
- c# - 无论泛型类型如何,我都可以设置一个模拟返回吗?
- flutter - 如何在 VS Code 中同时在 web 和 android 模拟器上运行颤振应用程序?
- c - 你如何在 C 中使用 scanf 识别输入不是数字?
- c# - 指定每个表模式的替代方法