【发布时间】:2022-01-09 22:49:13
【问题描述】:
我的 customer.component.ts 中有这个:
import { Component, OnInit, ViewChild, AfterViewInit } from '@angular/core';
import { NorthwindService } from 'swagger';
import {LiveAnnouncer} from '@angular/cdk/a11y';
import {MatSort} from '@angular/material/sort';
@Component({
selector: 'app-customers',
templateUrl: './customers.component.html',
styleUrls: ['./customers.component.scss']
})
export class CustomersComponent implements OnInit {
displayedColumns: string[] = ['id', 'name', 'contact', 'city', 'country', 'orders'];
customers!: any[];
constructor(private northwindService: NorthwindService, private _liveAnnouncer: LiveAnnouncer) { }
@ViewChild(MatSort) sort!: MatSort;
ngOnInit(): void {
this.northwindService.apiCustomersGet().subscribe(data => {
this.customers = data;
});
this.customers.sort = this.sort; <--- this wont't compile
}
}
this.customer.sort = this.sort; 出现了一些问题。
Iget 的错误是:
类型 'MatSort' 不能分配给类型 '(compareFn?: ((a: any, b: any) => number) | undefined) => any[]'。 类型 'MatSort' 不匹配签名 '(compareFn?: ((a: any, b: any) => number) | undefined): any[]'.ts(2322)
我看到的关于它的每个教程都有效。
【问题讨论】:
标签: angular angular-material material-design angular8