读取类型的参数:类型元素引用不可分配给类型属性的参数 静态 类型中缺少



我在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;

最新更新