gpt4 book ai didi

Angular ChangeDetectorRef : Cannot read property 'detectChanges' of undefined

转载 作者:行者123 更新时间:2023-12-01 23:55:40 27 4
gpt4 key购买 nike

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

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>

最佳答案

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

  selectTest = (e) => {
this.documentPropertyGridDataSelected = e.selectedRows;
this.cdr.detectChanges();
}

关于 Angular ChangeDetectorRef : Cannot read property 'detectChanges' of undefined,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62780478/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com