Angular导航后未显示mat-header-cell
创始人
2024-10-24 00:00:07
0

此问题通常出现在使用Angular Routing时,因为组件更改导致表格头部单元格(mat-header-cell)未显示。

有两种解决方案:

1.在AppComponent中,添加以下代码:

import { Router, NavigationEnd } from '@angular/router'; import { filter } from 'rxjs/operators';

export class AppComponent { constructor(private router: Router) { this.router.events.pipe( filter((event) => event instanceof NavigationEnd) ).subscribe(() => { setTimeout(() => { // 延迟 250 毫秒以确保 Angular 中的导航完成 const matHeaderCells = document.querySelectorAll('.mat-header-cell'); matHeaderCells.forEach(cell => { cell.style.width = ${cell.clientWidth}px; }); }, 250); }); } }

这将在每次导航结束时,获取所有的表格头部单元格(mat-header-cell)并设置它们的宽度。

2.使用样式文件中的CSS代码,将以下代码添加到全局样式中:

.mat-header-cell { width: fit-content !important; }

这将使表格头部单元格(mat-header-cell)自适应其内容的宽度。

此外,还需要检查是否已正确导入MatTableModule并确保在页面中正确使用标记和相关的组件和指令。

相关内容

热门资讯

四分钟辅助!we-poker有... 四分钟辅助!we-poker有人玩吗,wepoker免费脚本咨询,演示教程(有挂教程)wepoker...
八分钟辅助!aa poker辅... 八分钟辅助!aa poker辅助,pokemmo内置修改器,方式教程(证实有挂)1、完成pokemm...
第2分钟辅助!智星菠萝透视,h... 第2分钟辅助!智星菠萝透视,hhpoker到底可以作弊码,策略教程(有挂规律)1、hhpoker到底...
第1分钟辅助!wepoker怎... 第1分钟辅助!wepoker怎么发冤家牌,pokemomo辅助软件,办法教程(有挂解惑)1、wepo...
第1分钟辅助!德普之星辅助工具... 第1分钟辅助!德普之星辅助工具如何打开,德州局hhpoker,总结教程(有挂辅助)1、进入游戏-大厅...
第九分钟辅助!wepoker私... 第九分钟辅助!wepoker私人局俱乐部,德州圈脚本,妙招教程(有挂分享)暗藏猫腻,小编详细说明we...
第四分钟辅助!wpk模拟器,h... 第四分钟辅助!wpk模拟器,hhpoker辅助靠谱吗,技法教程(有挂讲解)1、完成hhpoker辅助...
第十分钟辅助!wepoker轻... 第十分钟辅助!wepoker轻量版辅助,wpk德州局透视,模板教程(有挂方针)wepoker轻量版辅...
七分钟辅助!wepoker透视... 七分钟辅助!wepoker透视最简单三个步骤,aapoker透视脚本入口,妙计教程(有挂秘籍)1、许...
四分钟辅助!佛手在线大菠萝辅助... 四分钟辅助!佛手在线大菠萝辅助,wepoker有透视底牌吗,演示教程(有挂规律)1、金币登录送、破产...