No output emitted when value changed to initial value set from Subject.next()
See original GitHub issueSo, I’m not sure if this is an issue with ngx-sub-form
or my understanding of how to accomplish this. I want to be able to set the initial value of a select or radio button of an ngx-sub-form
’s NgxAutomaticRootFormControl
or NgxRootFormControl
. I tried using the technique described on the blog https://dev.to/maxime1992/building-scalable-robust-and-type-safe-forms-with-angular-3nf9 where it mentions under spaceship-container.component.ts
to use an rxjs
Subject
and call it’s .next()
method. This does work, but then if I change a value of the select/radio and then try to go back to the initial choice, with the auto method I get no output and with the manual method I get the previous value instead. It happens whether the value is a primitive type (like string) or an object or array.
I’ve tried to simplify showing this off in the following StackBlitz: https://stackblitz.com/edit/ngx-sub-form-initial-next
The 4 forms are to show the different scenarios I figured would experience this problem, 2 with NgxAutomaticRootFormControl
and 2 with NgxRootFormControl
, each having a version for an array object as value and a string as value.
In app.component.ts
, I have a variable called doInitialNext
. If it is false
, no initial value is set and even going back to the null value of each select still emits the correct output. But when set to true
(as the example is set to), the value sent from ngAfterViewInit
is not emitted either automatically or manually when it is selected again later.
One other thing to note is that overriding emitInitialValueOnInit
to true
in any of the form components has no effect on this.
If this isn’t a bug in ngx-sub-form
, then I’d like to know what I’m doing wrong (and perhaps the blog post should be edited to not include that). I’ve dug a tad into the code, though, and it seems that NgxRootFormComponent
’s dataInputUpdated
is never called and the check in its onRegisterOnChangeHook
against this.dataInput$.value
is part of the problem. Perhaps I’m wrong, though.
Issue Analytics
- State:
- Created 4 years ago
- Comments:6
Top GitHub Comments
The reason I used
[ngValue]
instead of[value]
is because the former allows for objects while the latter only allows strings. It’s a subtle difference. Kinda weird that it works fine withngx-sub-form
, though.Although, making the change you suggested works on the array examples but not on the string examples. Those still don’t emit the new value when changing back to the one sent by
.next()
.☝️ Already closed because turns out that ngValue does work correctly once the fix was applied on your example.