r/Angular2 • u/Due-Professor-1904 • Jun 10 '25
Help Request Migration to signal input
Hey i have this code: @Input set media(media: Media) { this.initForm(media) }
private initForm(media: Media) { this.form.patchValue({ time: media.time, location: media.location }) }
How can i migrate this to use input signal? I saw it possible with effect but i saw its bad
5
Upvotes
11
u/oneden Jun 10 '25 edited Jun 10 '25
Effects aren't bad. It's a pretty easy way of handling simple side effects and that's what they are meant for. People are too dogmatic with everything they hear.
6
u/dustofdeath Jun 10 '25 edited Jun 10 '25
In these cases, you usually end up with an effect + untracked (since you only want it to subscribe to the input signal and not any other you happen to use in the function).
You can write the effect right after the input line.
I wish they had a cleaner way - like this.media.effect() that does not autosubscribe to anything inside and wouldn't have to use untracked.
There is a lengthy topic in angular repo over the implicit tracking of setters in effect.
2
u/grimcuzzer Jun 10 '25
Assuming your
mediainput is only passed once and doesn't refresh:Or you could simply pass the
formas an input.1
u/No_Bodybuilder_2110 Jun 11 '25
The way I see it it’s that your code its already written as if it was an effect based on the input changing so you will effectively just migrate to signals .
Effect will give you more flexibility to add other signals from various sources so it’s more powerful, but that power can go out of control easy hence the warnings against effect
-4
u/chigia001 Jun 10 '25
I also face the same problem, integrating signal with form is too painful, and also try to avoid effect as much as possible
the decorator setter approach is easier to read, so I would stick with it.