角度:未检测到管道变化 [英] Angular: Change in Pipe not detected
本文介绍了角度:未检测到管道变化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这个管道,它将 input 值乘以从服务检索到的另一个值:
I have this pipe which multiplies the input value by an other value retrieved from a service:
@Pipe({
name: 'multiply'
})
export class MultiplyPipe implements PipeTransform {
constructor(private service: StateService) { }
transform(value: any, args?: any): any {
return value * this.service.multiplier;
}
}
用法:
{{ value | multiply }}
这很好用,但是当服务中的multiply
值被更改时,它不会触发任何更改检测,因此
This works fine, but when the multiply
value from the service is changed, it doesn't trigger any change detection, and thus
{{ value | multiply }}
不会再次运行,将旧值保留在屏幕上.有什么建议可以解决吗?
is not run again, leaving the old value on the screen. Any suggestion how this can be fixed?
推荐答案
如 Angular文档,如此stackblitz 所示,这是强制实施的一种方法要调用的管道是不纯的:
As discussed in Angular documentation, and as shown in this stackblitz, one way to force the pipe to be called is to make it impure:
@Pipe({
name: 'multiply',
pure: false
})
For more details about pure and impure pipes, you can see this article.
这篇关于角度:未检测到管道变化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文