Closed grosch closed 3 years ago
Please reproduce on stackblitz
I tried to create a stackblitz for you but that doesn't work as ngcc fails to run against @ngneat/reactive-forms now. However, I was able to simplify it down to this example that will show the failure if you paste it into your project:
export abstract class DetailForm<T> implements OnInit {
formGroup!: FormGroup<T>
public onChange?: (x: T | null) => void
ngOnInit(): void {
this.formGroup.value$.subscribe(x => {
this.onChange?.(x)
})
}
}
Any help you can provide here?
@NetanelBasal Any updates? I'd love to reproduce on stackblitz but if I add @ngneat/reactive-forms then ngcc fails there.
You can use codesandbox
OK, I found that my CVA was conflicting with your ControlValueAccessor
Try this:
import { Directive } from "@angular/core";
import { FormGroup, ControlValueAccessor, } from "@ngneat/reactive-forms";
import { ControlsValue } from "@ngneat/reactive-forms/lib/types";
@Directive()
export abstract class AbstractDetailForm<T extends Record<any, any>> extends ControlValueAccessor<T> {
public abstract readonly formGroup: FormGroup<T>;
writeValue(obj: ControlsValue<T> | null | undefined): void {
if (obj)
this.formGroup.setValue(obj);
}
}
ControlsValue
is now exported in v2.
I'm submitting a...
Current behavior
A
FormGroup
'svalue$
observable emits aControlsValue<T>
instead of aT
.Expected behavior
I want to actually get a value of type
T
so that I can do this:That doesn't work though because
x
there isn't actually of typeT
I'm doing nested forms, and so when this form changes, I pass the value up to the parent's control.
Environment