Using Angular 15+ hostDirectives, how can I bind to inputs of the directive?
Note that I don't want to forward directive inputs to the host component, making them inputs of the component. I want to bind an expression to one of the directive inputs.
@Directive({
standalone: true,
})
class MyDirective {
@Input()
directiveInput?: string;
}
@Component({
hostDirectives: [ MyDirective ],
host: {
'[directiveInput]': 'inputValue' // This won't work, even if `directiveInput` is defined in the inputs of host directive definition object.
}
})
class MyComponent {
inputValue: string;
}
I sure can inject the directive, and assign the input manually in ngOnInit. But:
I'll quote one of the member of the angular team here:
The composing directive can not provide values to host directive inputs.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With