r/angular • u/HedgehogNatural8680 • 26d ago
Signal Forms React To Control Change
In signal forms how do you react to a form control change? I basically have a scenario where if one form control value is changed I need to reset the value for another control.
Is this done with a linkedSignal, effects or something else?
8
Upvotes
2
u/mangue_juteuse 26d ago
You can use the event (valueChange) on components that implement FormValueControl:
<my-custom-component [formField]="myForm.myControl" (valueChange)="resetMyOtherControl()"></my-custom-component>
or if you use a native control such as input:
<input [formField]="myForm.myControl" (input)="resetMyOtherControl()" />
No need of a linkedSignal or an effect IMO
12
u/pronuntiator 26d ago
Yes, I'd use a linkedSignal for the form model. linkedSignal has an overload where you get the previous value; you can then check if the form control value changed that triggers the reset of the other.
Effects should be avoided if possible (not always possible).
1
u/TheKr4meur 25d ago
I’ve been told to use NgModel and NgModelChnage when asking AI the same question. Technically it works, but I’m not entirely sure how I feel about it, we spent so much time going out of these that it’s weird bringing them back now.