角材料表排序-在* ngIf条件中时,数据不排序 [英] Angular Material Table Sorting - Data Doesn't sort when inside a *ngIf condition

查看:89
本文介绍了角材料表排序-在* ngIf条件中时,数据不排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个角材料表.当我用<div *ngIf="true">包围表格的html时,表格将呈现,但单击标题列时数据不再排序.

I have a Angular Material Table. When I surround html for the table with a <div *ngIf="true"> the table renders but the data no longer sorts when clicking on the header column.

以以下示例为例: https://material.angular.io/components/表格/概述#sorting

并对其进行修改,只需添加<div *ngIf="true"> ... </div>即可演示此行为.示例如下: https://stackblitz.com/edit/angular-quzvjv

And modifying it, just by adding the <div *ngIf="true"> ... </div> demonstrates this behavior. Example is at: https://stackblitz.com/edit/angular-quzvjv

推荐答案

在控制台上登录this.sortngOnInit

在初始化阶段NgIf未处理模板时,Angular没有捕获到MatSort组件.

Angular didn't catch MatSort component as on init phase NgIf didn't process the template.

ngOnInit更改为ngAfterViewInit,它将按预期工作.

Change ngOnInit to ngAfterViewInit and it will work as expected.

这篇关于角材料表排序-在* ngIf条件中时,数据不排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆