我正在使用Angular 5.x模板,但是我使用https://update.angular.io/指南将其升级到Angular 6 。现在我的构造函数中有这个错误
Typescript Error: TS2314: Generic type 'ElementRef<T, any>' requires 2 type argument(s)
Run Code Online (Sandbox Code Playgroud)
我的代码:
import { Component, Input, Output, EventEmitter, ElementRef, HostListener } from '@angular/core';
@Component({
selector: 'sidebar',
templateUrl: './sidebar.component.html'
})
export class SidebarComponent {
@HostListener('document:click', ['$event'])
clickout(event) {
if(!this.eRef.nativeElement.contains(event.target)) {
this.hideMobileSidebar.emit(true);
}
}
constructor(private eRef: ElementRef) {
}
...
Run Code Online (Sandbox Code Playgroud)
我在以前的Angular版本5中没有此错误。
有什么变化?我不理解文档:( https://angular.io/api/core/ElementRef
我需要将mat-table组件的Header固定在顶部,但这不起作用。
我有Angular v6.1.7和@ angular / material v6.4.7。
我在matHeaderRowDef上添加了“ sticky:true”属性,就像有人在这里提到的那样,但是它什么也没做:(
<tr mat-header-row *matHeaderRowDef="displayedColumns; sticky: true"></tr>
Run Code Online (Sandbox Code Playgroud)
我有这个示例项目:https : //stackblitz.com/edit/angular-wem2qa
这是我在TS文件上的导入:
import { Component, Input, OnChanges, OnInit, SimpleChanges, ViewChild } from "@angular/core";
import { MatDialog, MatExpansionPanel, MatSnackBar, MatSort, MatTableDataSource, Sort } from "@angular/material";
Run Code Online (Sandbox Code Playgroud)