Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular ChangeDetectorRef: Cannot read property 'detectChanges' of undefined

I am receiving the following error with ChangeDetectorRef. Not sure why its suddenly occurring, when other components utilize ChangeDetectorRef. Does anyone know how to solve? Its linking to a Kendo Grid selection.

TypeError: Cannot read property 'detectChanges' of undefined

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();
  }

HTML:

<div>
  Selected Count: {{documentPropertyGridDataSelected.length}}
<div>

1 Answers

Probably the this context (BTW, how is the function called?). Fixable by converting it to an arrow function

  selectTest = (e) => {
    this.documentPropertyGridDataSelected = e.selectedRows;
    this.cdr.detectChanges();
  }
like image 192
mbojko Avatar answered Feb 01 '26 03:02

mbojko



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!