Angular 无法设置属性';过滤器预测';角材料表中未定义误差的分析

Angular 无法设置属性';过滤器预测';角材料表中未定义误差的分析,angular,asynchronous,angular-material,observable,Angular,Asynchronous,Angular Material,Observable,我有一个带有客户端过滤的Angular Material表,其中我从服务中检索数据。当我的过滤器能够正确处理硬编码数据时,我收到一个错误提示:自从我切换到从服务检索数据以来,无法将属性'filterPredicate'设置为undefined。数据在我的表中正确可见,但我无法对其进行筛选 export class MessageTableComponent implements OnInit { datasource: any; } ngOnInit() { t

我有一个带有客户端过滤的Angular Material表,其中我从服务中检索数据。当我的过滤器能够正确处理硬编码数据时,我收到一个错误提示:自从我切换到从服务检索数据以来,无法将属性'filterPredicate'设置为undefined。数据在我的表中正确可见,但我无法对其进行筛选

export class MessageTableComponent implements OnInit {
    datasource: any;
}
    ngOnInit() {

        this.messageService.getMessageTableData().subscribe(
          response => {
            this.dataSource = new MatTableDataSource(response);
            console.log(response);
          }
        );

        this.RequestIdFilter.valueChanges.subscribe((RequestIdFilterValue) => {
          this.filteredValues['RequestID'] = RequestIdFilterValue;
          this.dataSource.filter = JSON.stringify(this.filteredValues);
          });

          this.RequestStatusFilter.valueChanges.subscribe((RequestStatusFilterValue) => {
            this.filteredValues['RequestStatus'] = RequestStatusFilterValue;
            this.dataSource.filter = JSON.stringify(this.filteredValues);
            });

          this.RequestorNameFilter.valueChanges.subscribe((RequestorNameFilterValue) => {
            this.filteredValues['RequestorName'] = RequestorNameFilterValue;
            this.dataSource.filter = JSON.stringify(this.filteredValues);
          });

          this.ApproverNameFilter.valueChanges.subscribe((ApproverNameFilterValue) => {
            this.filteredValues['ApproverName'] = ApproverNameFilterValue;
            this.dataSource.filter = JSON.stringify(this.filteredValues);
          });

          this.SubjectFilter.valueChanges.subscribe((SubjectFilterValue) => {
            this.filteredValues['Subject'] = SubjectFilterValue;
            this.dataSource.filter = JSON.stringify(this.filteredValues);
          });

          this.MessageStatusFilter.valueChanges.subscribe((MessageStatusFilterValue) => {
            this.filteredValues['MessageStatus'] = MessageStatusFilterValue;
            this.dataSource.filter = JSON.stringify(this.filteredValues);
            });

            this.SubmissionFromDateFilter.valueChanges.subscribe((SubmissionFromDateFilterValue) => {
              this.filteredValues['SubmissionFromDate'] = SubmissionFromDateFilterValue;
              this.dataSource.filter = JSON.stringify(this.filteredValues);
            });

            this.SubmissionToDateFilter.valueChanges.subscribe((SubmissionToDateFilterValue) => {
              this.filteredValues['SubmissionToDate'] = SubmissionToDateFilterValue;
              this.dataSource.filter = JSON.stringify(this.filteredValues);
            });



        this.dataSource.filterPredicate = this.customFilterPredicate();

        this.dataSource.sort = this.sort;


      }

customFilterPredicate() {
.....
}
错误显然在最后一行的第二行。messageService是我用来检索数据的服务,其余的代码是在任何列的值发生变化时过滤数据。下面是我的customFilterPredicate函数,它为每一列定义过滤器


我不明白是什么问题。我已经在ngOnInit中定义了dataSource,那么为什么会出现错误以及如何解决它?

当执行此行“this.dataSource.filterPredicate=this.customFilterPredicate();”时,您的服务调用没有返回

我们知道异步调用可能需要时间(与获取硬编码数据相比)

试着把这两行(上面)放在ServiceCallFinally块中,我还包括了一个错误块,您应该总是要处理任何错误

   this.messageService.getMessageTableData().subscribe(
          response => {
            this.dataSource = new MatTableDataSource(response);
            console.log(response);
          }
          ,errorResponse => { console.log(errorResponse); }
          ,()=> { 
            this.dataSource.filterPredicate = this.customFilterPredicate();
            this.dataSource.sort = this.sort;
            }
            );
   this.messageService.getMessageTableData().subscribe(
          response => {
            this.dataSource = new MatTableDataSource(response);
            console.log(response);
          }
          ,errorResponse => { console.log(errorResponse); }
          ,()=> { 
            this.dataSource.filterPredicate = this.customFilterPredicate();
            this.dataSource.sort = this.sort;
            }
            );