angular - Angular ChangeDetectorRef:无法读取未定义的属性“detectChanges”
问题描述
我收到 ChangeDetectorRef 的以下错误。不知道为什么它突然发生,当其他组件使用 ChangeDetectorRef 时。有谁知道如何解决?它链接到剑道网格选择。
TypeError:无法读取未定义的属性“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();
}
HTML:
<div>
Selected Count: {{documentPropertyGridDataSelected.length}}
<div>
解决方案
可能是this
上下文(顺便说一句,函数是如何调用的?)。可通过将其转换为箭头函数来修复
selectTest = (e) => {
this.documentPropertyGridDataSelected = e.selectedRows;
this.cdr.detectChanges();
}
推荐阅读
- excel - Excel Vb 向多个收件人发送电子邮件
- database - 添加新数据时的Java FX数据库问题
- spring - 使用 Spring 和 Apache 文件上传时如何模拟多部分文件上传
- git - jenkins git clone 错误:克隆远程 repo 'origin' 时出错
- angularjs - Visual Studio Code 上的 Angular:如何显示数据库中的图像?
- javascript - 无法验证收据错误:无法使用 Node.js 验证购买
- java - 开始使用必发的 Java Streaming API
- java - Java Map 实现渐近复杂度(HashMap、LinkedHashMap、TreeMap)
- bash - wget 用原始名称重命名
- amazon-web-services - Terraform Route53 数据