Skip to content
Learn Netverks
2

Angular pipe not reacting to observable/signal?

asked 15 hours ago by @qa-aepm4homq2xa4wwyr83w 0 rep · 61 views

angular angular pipe

@Pipe({
    name: 'myNumber',
    pure: false,//not working with true
    standalone: true
})
export class VNumberPipe implements PipeTransform {

    intl = inject(IntlService);
    translate = inject(TranslateService);
    cdr = inject(ChangeDetectorRef);

    lang$ = new BehaviorSubject<string>(this.translate.currentLang);

    constructor() {
        this.translate.onLangChange.pipe(takeUntilDestroyed()).subscribe(l => this.lang$.next(l.lang));
        this.lang$.pipe(
            //skip(1),
            takeUntilDestroyed()
        ).subscribe(() => this.cdr.markForCheck()); //Not working?
    }

    transform(value: number, format: string): string {
        return this.intl.formatNumber(value, format, this.lang$.value);
    }
}

That code is not working somehow, what we would like si whnever the lang$ changes that automatically the cache is invalidated of the pipe, so pipe can be pure unless the use case is that really language changed, what should someone do in this case?

Update: Apperently not possible right now because it cannot be pure while values not change and side effect needing to retrigger the pipe execution. Discussion is moved under: https://github.com/angular/angular/issues/69767

Comments on this question (0)

Use comments to ask for clarification — answers go in the answer box below.

Log in to comment on this question.

0 answers

Your answer