Hi guys,
we have a ControlValueAccessor component, which has another form inside of it, and we are sending the values from the nested form up to its parent.
In constructor we have private readonly destroyRef: DestroyRef,
and the registerOnChange looks like this:
registerOnChange(fn: any): void {
this.translationsForm.valueChanges
.pipe(
map((translation: Translation) => {
translation.translations.forEach(t => (t.content = t.content ? t.content : ''));
return translation;
}),
takeUntilDestroyed(this.destroyRef)
)
.subscribe(fn);
}
And when we navigate out of the route, so the component is destroyed, we get this error in console:
zone.js:177 Uncaught Error: NG0911: View has already been destroyed.
at storeLViewOnDestroy (core.mjs:3180:15)
at NodeInjectorDestroyRef.onDestroy (core.mjs:10593:9)
at Observable._subscribe (rxjs-interop.mjs:27:41)
at Observable._trySubscribe (Observable.js:37:25)
at Observable.js:31:30
at errorContext (errorContext.js:19:9)
at Observable.subscribe (Observable.js:22:21)
at takeUntil.js:7:29
at SafeSubscriber.<anonymous> (lift.js:10:28)
at Observable.js:26:30
I googled, I asked AIs, I looked everywhere, but I can't find anything about this specific bug. Can you tell me what are we doing wrong please?