AngularMatSort.Typeismissing
创始人
2024-10-28 12:01:19
0

这个错误信息通常是在Angular中使用MatSort时出现的,它表示需要为MatSort指定一个sort的Type类型。

以下是一个示例代码:

HTML代码:

Name Age Email
{{user.name}} {{user.age}} {{user.email}}

TypeScript代码:

import { MatTableDataSource, MatSort } from '@angular/material';

@Component({ selector: 'app-users', templateUrl: './users.component.html', styleUrls: ['./users.component.css'] }) export class UsersComponent implements OnInit { displayedColumns = ['name', 'age', 'email']; dataSource = new MatTableDataSource(); @ViewChild(MatSort, {static: true}) sort: MatSort;

ngOnInit() { this.dataSource.data = this.users; this.dataSource.sort = this.sort; }

sortData(sort: MatSort) { const data = this.users.slice(); if (!sort.active || sort.direction === '') { this.dataSource.data = data; return; } this.dataSource.data = data.sort((a, b) => { const isAsc = sort.direction === 'asc'; switch (sort.active) { case 'name': return compare(a.name, b.name, isAsc); case 'age': return compare(a.age, b.age, isAsc); case 'email': return compare(a.email, b.email, isAsc); default: return 0; } }); } }

function compare(a: number | string, b: number | string, isAsc: boolean) { return (a < b ? -1 : 1) * (isAsc ? 1 : -1); }

在代码中,我们使用了MatSort模块并初始化了一个sort变量,这意味着我们使用了一个

相关内容

热门资讯

透视系统!wpk辅助ai,we... 透视系统!wpk辅助ai,wepoker怎么设置透视(详细辅助微扑克教程)1、游戏颠覆性的策略玩法,...
德扑ai助手!wepoke是不... 德扑ai助手!wepoke是不是有挂(透视)原本真的有挂(详细辅助黑科技教程)1)德扑ai助手辅助挂...
透视插件!wepoker透视脚... 透视插件!wepoker透视脚本苹果,菠萝辅助器免费版的功能介绍(详细辅助新2025教程);该软件可...
aapoker外挂!wepok... aapoker外挂!wepoke软件收费是真的吗(透视)本来存在有挂(详细辅助黑科技教程)1、这是跨...
透视app!红龙poker透视... 透视app!红龙poker透视工具,wepoker辅助脚本(详细辅助微扑克教程)一、红龙poker透...
wepoke辅助技巧!wepo... wepoke辅助技巧!wepoke里面有ai吗(透视)起初有挂(详细辅助分享教程)是一款可以让一直输...
透视辅助!wepoker辅助器... 透视辅助!wepoker辅助器下载,wejoker辅助器怎么卖(详细辅助AI教程)1)wepoker...
wpk提高胜率!wepkoe有... wpk提高胜率!wepkoe有外挂么(透视)从来有挂(详细辅助大神讲解)wpk提高胜率辅助器中分为三...
wepoke真的有挂!wepo... wepoke真的有挂!wepoke管理系统(透视)本来有挂(详细辅助攻略方法);无聊就玩这款wepo...
透视真的!wpk透视工作室,h... 透视真的!wpk透视工作室,hh poker插件下载(详细辅助wepoke教程);暗藏猫腻,小编详细...