I wanted to create a directive that sets an inputSignal of a component, but I was not able to.
@Component({
selector: '[my-component]',
standalone: true,
template: `{{content()}}`,
})
export class MyComponent {
public readonly content = input<string | undefined>(undefined, {
alias: 'my-component',
});
}
@Directive({
selector: '[my-component][withPredefinedContent]',
standalone: true,
})
export class MyDirective implements AfterContentInit {
private readonly component = inject(MyComponent, { host: true });
ngAfterContentInit() {
this.component.content.set(`I can't do this`); // <-- I can't do this. ⭕
}
}
With a setter @Input
I could do it, but I’d like to use the new signal approach.
Any idea how could I achieve this or a function similar to this?
I have a Stackblitz example