mangusbrother
mangusbrother

Reputation: 4154

Pipe with ChangeDetectorRef not being refreshed on subscription event

I have the following pipe:

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

}

However when the event emitter outputs an event the value of the pipe is not reobtained.

Upvotes: 0

Views: 433

Answers (1)

Günter Zöchbauer
Günter Zöchbauer

Reputation: 657781

Angular change detection checks the value and the parameters passed to a pipe for change. If they don't change, calling markForCheck() is just a waste of CPU.

A workaround could be to use pure: false and return the cached result until myEventEmitter emits an event.

Upvotes: 1

Related Questions