我有以下管道:
{{ "value" | translationPipe | async }}
translationPipe {
constructor(otherService: OtherService, myService: MyService, _ref : ChangeDetectorRef) {
this.myService.myEventEmitter.subscribe(value -> {
_ref.markForCheck();
});
}
transform(value, args?) {
// this returns an api call observable
return this.otherService.doApiCall();
}
}
但是,当事件发射器输出事件时,不会重新获取管道的值。
最佳答案
Angular 变化检测检查传递到管道的值和参数以进行更改。如果它们不改变,调用 markForCheck()
只是浪费 CPU。
解决方法可能是使用 pure: false
并返回缓存的结果,直到 myEventEmitter
发出事件。
关于javascript - 订阅事件时未刷新具有 ChangeDetectorRef 的管道,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45148835/