Repository navigation
Description
Which @angular/* package(s) are relevant/related to the feature request?
core
Description
With Input signals they are read-only which forces any consumer of the component to have to set the Inputs through the template. For some situations with a parent/child relationship (such as projected content) the parent needs to be able to programmatically set values of the Inputs as they don't have access to set the template bindings.
As a component library author there are often cases where we allow something like an icon component to be projected. The icon component has an input that allows several sizes. When the icon is used in a specific component in a projection slot that component can query through a ContentChildren query. That component can further set the value of the @Input to "enforce" a given size. This "parent" component can't set the value through the template bindings as it doesn't have template access to projected content, just component class instances.
Here's a non-working example of where a parent component allows projected icon components. It is trying to query for icon content and then set the size input. We've been able to accomplish in the past with @Inputs and the getter/setter pattern. We'd love to be able to move to Input signals but this blocks us.
Proposed solution
Some way for consumers to set the value of an Input programmatically. I realize they are read-only but this breaks the notion of a component not knowing how it is consumed and used. Consumers are allowed to set Inputs through the template OR through the component class instance with a reference.
Alternatives considered
We can continue to use a getter/setter syntax to fake Input signals. Something like this:
@Input() get size(): number {
return this._size;
}
set size(value: number) {
this._size.set(value);
}
private _size = signal();
It would be nicer and easier to maintain if we can utilize Input signals programmatically.
Model Inputs are also a potential option
I don't feel that the Model inputs are the solution here as that would mean all of our Inputs would have to be Model inputs because as component library authors we don't know how a consumer will access our Inputs (via template or programmatically). Whereas Model inputs more feels like it's trying to solve ControlValueAccessor stuff and not necessarily meant for this.
Activity
Harpush commentedon Mar 8, 2024
One can say it is half way related to #47398
As injecting the component ref of the projected component (in this case with content child) would allow setInput usage
Fernker commentedon Mar 8, 2024
@Harpush is the
setInputavailable automatically when using@ContentChildren? I've only used it with dynamic components and still am not clear if it's currently available?Harpush commentedon Mar 8, 2024
No it isn't. The issue I linked suggest adding it to injection of host component from directive. This issue seems half way similar as it can be solved if content child could get not the component instance but the component ref instead.
Fernker commentedon Mar 8, 2024
Although
setInputseems pretty broadly typed, which might make sense with a ComponentRef but it would need to be narrower to be most useful.Harpush commentedon Mar 8, 2024
There is an open issue for better setInput types too
Fernker commentedon Mar 8, 2024
Would the
componentRefstill include a reference to the component class to be able to access other methods on the class that aren't inputs?RobbyRabbitman commentedon Mar 15, 2024
I had a similar situation, which was solved by unwrapping the Signal Input with the SIGNAL symbol and use setSignalValueFn (or something like that... typing this comment from mobile). I don't know if that's intended, but it worked :D
alxhub commentedon Mar 28, 2024
@RobbyRabbitman just note that
SIGNALisn't public API.[-]Support for setting Input Signals programmatically for projected content children[/-][+]Support for setting Input Signals programmatically given a directive instance[/+]thaoula commentedon Dec 19, 2024
@alxhub could we get a method that does what @RobbyRabbitman in a supported way?
We have directives that would like to update their host components. I have created a simplified example here:
https://stackblitz.com/edit/stackblitz-starters-jxjmiswb?file=src%2Fmain.ts
In real life the host component is something similar to NGSELECT with many inputs
I have also commented on the issue regarding getting a reference to ComponentRef to utilise set input.
#47398 (comment)
DaSchTour commentedon Dec 27, 2024
I have a somehow related issue while migrating to signal inputs. I have several directives that are used to programmatically set the inputs of another directive that is connected through hostDirectives and then injected into my directive.
Or am I missing some undocumented API that makes it possibility to set the inputs of host directives programmatically?
60 remaining items
hakimio commentedon Nov 25, 2025
@splincode there is already a writable
input(), it's calledmodel(). The main issue here is thatinput()is not writable from directives and you can't do things like this.mauriziocescon commentedon Nov 25, 2025
Well,
modelis also doing the "right thing": in case, same value between parent and child. Which is never true for inputs, no matter what. As long as you own the entire stack of components,modelis more or less what you need: see signal-forms.IMO the entire ticket is mostly related to components you don't own...
Regarding the other frameworks, I'm not aware of any one where inputs are writable (forbidden / discouraged / ...). All the others:
As usual ☮️
https://stackblitz.com/edit/stackblitz-starters-gvt2ylbo
Ketec commentedon Nov 25, 2025
Model has its own issues.
I recall that the value did not reflect or trigger back when you used createComponent and setInput. Not sure if 21 fixed that.
Linters also tend to suggest that model should be set readonly.
Its likely only meant for two way binding through template (the banana in a box).
It does not have transform support.
Migration script auto creates input signal.
So you are quickly going to have new lib releases that just went for input.
Its not official either, so it can easily break in 22+ and again all the directives will fail.
The longer this is left unsolved, the worse it all gets.
People writing all kinds of custom hacks and workarounds.
It should have been a drop in replacement like signals in templates were, without breaking millions of directives across codebases.
Erbenos commentedon Nov 25, 2025
Thing is the old input setting never actually worked fully, but only by coencidence - either the properties were backed by getter/setter pairs, or they were never observed in any lifecycle hooks. So its not like the signal inputs broke anything - they just invalidated an approach that always depended on internal component implementation details, whether users were aware of it or not.
mauriziocescon commentedon Nov 25, 2025
Well,
createComponentlet you specify bindings now. And in a template, you can just bind to a model like an input (<Child setter [value]="v1()" />). So, onlytransformas far as I know (which - by the way - makes sense it's missing).I agree the doc could be more clear and the migrations can be misleading (but ok: IMHO it's not a drama either ).
https://stackblitz.com/edit/stackblitz-starters-y2d9ac6d?file=src%2Fmain.ts
splincode commentedon Nov 26, 2025
@hakimio sure, but what if I don’t need output event in component?
hakimio commentedon Nov 26, 2025
I think it depends. If you are modifying the input inside your component, you usually do want to have the modified value reflected in a two-way-binding (there are exceptions, of course). On the other hand, if you are modifying some component (can also be UI library component) input from a separate directive or some other 3rd party context, you shouldn't be required to convert the
input()tomodel()signal.Anyway,
input()signal should just be a writable signal without having to resort to any special configs/flags or other hacks. It should be writable by default. The "race condition" contra-argument is a moot point - we have been updating Angular inputs since forever and nobody complained about it.input()signal should be fully backward compatible with@Input(). The community has expressed a clear need for this functionality and Angular framework devs (@alxhub) shouldn't just ignore it as if it's some minor issue nobody cares about.pburgmer commentedon Nov 26, 2025
I don't agree on 'inputs should be writable'. You shouldn't change the value of in input from within the component. That's code smell and caused some serious trouble in our code base. We need to be able to change the input from the outside in some scenarios like directive. That's something completely different. It could be solved by having something like a DirectiveRef or ComponentRef which allows interaction with the component the same way Angular is dealing with it.
MillerSvt commentedon Nov 26, 2025
I agree. Inputs should not be writable. But since inputBindings already works in
createComponentmethod, I can't find any reason not to do the same in components.I already posted (as I think) good solution for this problem:
I think this solution can solve most of use cases in this thread.
waterplea commentedon Nov 26, 2025
@MillerSvt that's good UX and it would solve #50510 but this would absolutely not be enough.
Ketec commentedon Nov 26, 2025
For example:
You want to set several defaults and utilities to standardize the usage for your product.
There may be a 100 of these across the product.
You still want to access the kendo-multiselect inputs and outputs. There is no way to automatically extend and proxy everything.
This component hostDirective in a component wrapper does not help here.
fix: Workaround for 'ariaLabelDropdown' input signal (#20862)
montella1507 commentedon Dec 1, 2025
I wonder how is implemented that new [field] directive in Signal base forms...
If you want to get "notifications" about control state, you can implement this interface:
https://angular.dev/api/forms/signals/FormUiControl
as you can see, there are mainly Inputs() and not Models..
And field (or something above) has to be able to set those inputs...
So it is Directive => Component input scenario.
However i wasnt able to find the implementaiton how it is done.
LoaderB0T commentedon Oct 21, 2026
Three concrete cases from a signal-only component library on v22 (jig), all currently solved with a
SIGNALhack:inject(Comp, { self: true })). The template author never sees the value, so they can't bind it.viewChildren. The children are also used standalone with their own binding, so neithermodel()nor a duplicate internal signal fits.Core in v22 already does case 1, privately.
ɵɵControlFeaturegives Signal Forms'FormFielda host whosesetInputOnDirectives()writes inputs of the other directives on the same node viawriteToDirectiveInput. That path applies transforms, callsngOnChangesand resolves host-directive aliases, so it doesn't have the problems raised in #55082. The user-land hacks skip transforms and rely on private API.Could this be triaged? Exposing that same-element capability publicly would already cover most cases here.
Reality is, it used to work with the old @input() syntax and doesn't work with signal inputs without workarounds. So why not make these workarounds official ? :)