【问题标题】:how to dynamically show a mat-progress-bar when a button is clicked单击按钮时如何动态显示mat-progress-bar
【发布时间】:2020-12-07 16:52:45
【问题描述】:

您好,我在我的 mat-table 中过滤了大约 6000 行数据,当单击“过滤器”按钮时,过滤需要大约 5 秒。我试图在调用函数时显示一个 Mat-Progress-Bar。我附上了一个示例 stackblitz 来尝试重现我的问题。我希望 Mat-Progress-Bar 仅在单击“过滤器”按钮时显示,并在呈现数据时消失。

https://stackblitz.com/edit/angular-4ttand-8ckvs7?file=src/app/table-basic-flex-example.ts

<button mat-raised-button (click)="filterTable()"> Filter Table on Weight!</button>

<mat-progress-bar *ngIf="isLoading" color="primary" mode="indeterminate"></mat-progress-bar>

export class TableBasicFlexExample {
  isLoading = true

filterTable() {
         this.dataSource = this.dataSource.filter((item) => { 
         return Math.floor(item.weight) > 10});
         this.isLoading = false;
      }
}

【问题讨论】:

    标签: angular angular-material


    【解决方案1】:

    试试这个。

    https://stackblitz.com/edit/angular-4ttand-i6mwao?file=src/app/table-basic-flex-example.ts

    PS:不要忘记删除 setTimeout,我用它来“模拟”你的函数过滤所需的时间。

    filterTable() {
        this.isLoading = true
        this.dataSource = this.dataSource.filter((item) => { 
        console.log(Math.floor(item.weight));
        return Math.floor(item.weight) > 10});
        this.isLoading = false;
    }

    【讨论】:

    • 欢迎来到 Stack Overflow。请在答案中包含您对提问者问题的解决方案,而不是在外部网站中。但是,您可以保留外部 URL,以便用户可以尝试。
    • 谢谢,但这仍然不适用于我的数据源过滤器功能上的动态数据。
    • 在调整了我的一些 ngOnInit 逻辑后,我得到了这个工作
    • @MarcSances 我编辑了答案。我的错,这是我的第一个答案。
    猜你喜欢
    • 2019-06-16
    • 2018-03-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-08-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多