#Angular opinion for old code with rxjs refactor

1 messages · Page 1 of 1 (latest)

split sand
#

I have this old code that listens multiple times on different parts for reactive forms.
e.x.x form$.valueChanges
I want to use the new angular 19 signals and tidy it a bit.
I want to have it inside a function or multiple steps.

Question:
Can i use signals with that example for form$ observable

The form is bound into formbuilder and on the html as async.
The form gets assigned and assigns changes, that i do not like.

Any workaround?

@if (form$ async | as form) {
  <form [formGroup]="form">
    <mp-input formControlName="first_person"></mp-input>
  </form>
}

on that form$ i have too many side effects in methods with example of the following code. They are 4 assignments and some disabling enabling the form values and setting new values.

const itemSelectionValueChanges$ = form.get('itemSelection')!.valueChanges;
itemSelectionValueChanges$.subscribe(value => {
  
});

I want a way to keep making those changes in the form, but with less side effects and not all with valueChanges

coarse vortex
#

I have a hard time understanding your question. You should post a complete minimal reproduction.

split sand
coarse vortex
#

Well, valueChanges is the correct way to be notified when a value changes. Reactive forms don't expose any signal anyway. You could transform those valueCHanges into signals and then use effects, but I don't really see the point.
There might be improvements to make on the code, but without being able to see the code...

split sand
#

NOTE: The issue was it was assigning formGroup$ to form$ to formWithStuff$ and only use form$. When formGroup$ had a pipe with assigning services and two methods.

I wanted to have it in one without breaking anything. But i cant remove valueChanges. maybe make formGroup$ reactive as signal. But the valueChanges does not rerender.

coarse vortex
#

You're talking about code that we cannot see. We have no magic crystal ball. If you want help, post a complete minimal repro, as explained in #how-to-get-help

split sand
coarse vortex
#

Nobody asked for the whole code. I asked for a complete minimal reproduction of your issue. There's something you don't like about your code, so post a complete but minimal reproduction showing what you don't like about your code and your attempt at refactoring it showing the bug you mentioned above.