Angular ChangeDetectorRef:无法读取未定义的属性“detectChanges”

3 typescript angular angular-changedetection angular8

我在 ChangeDetectorRef 中收到以下错误。当其他组件使用 ChangeDetectorRef 时,不知道为什么它突然发生。有谁知道如何解决?它链接到 Kendo Grid 选择。

类型错误:无法读取未定义的属性“detectChanges”

export class DocumentPropertyGridComponent implements OnInit, OnChanges {

  public documentPropertyGridDataSelected: Array<DocumentPropertyGridData> = new Array<DocumentPropertyGridData>();

  constructor(private cdr: ChangeDetectorRef) { 
  }

  selectTest(e){
    this.documentPropertyGridDataSelected = e.selectedRows;
    this.cdr.detectChanges();
  }
Run Code Online (Sandbox Code Playgroud)

HTML:

<div>
  Selected Count: {{documentPropertyGridDataSelected.length}}
<div>
Run Code Online (Sandbox Code Playgroud)

mbo*_*jko 9

可能是this上下文(顺便说一句,该函数是如何调用的?)。可通过将其转换为箭头函数来修复

  selectTest = (e) => {
    this.documentPropertyGridDataSelected = e.selectedRows;
    this.cdr.detectChanges();
  }
Run Code Online (Sandbox Code Playgroud)