Skip to content

Reactive ComponentRef.setInput #57849

Description

@twittwer

Which @angular/* package(s) are relevant/related to the feature request?

core

Description

If I want to pass signal based data to a ComponentRef we have to set the input and create an effect to update the input.

const counterSignal = signal<number>(0) // signal from store or some service

const counterOverlayRef = createOverlay(); // using CDK Overlay
const counterComponentRef = counterOverlayRef.attach(new ComponentPortal(MyCounterComponent));
counterComponentRef.setInput('count', counterSignal());
effect(() => {
  counterComponentRef.setInput('count', counterSignal());
}, { injector: counterComponentRef.injector }); // using component ref injector to cleanup effect with component

Proposed solution

It would be nice to streamline this by passing the signal itself.

const counterSignal = signal<number>(0) // signal from store or some service

const counterOverlayRef = createOverlay(); // using CDK Overlay
const counterComponentRef = counterOverlayRef.attach(new ComponentPortal(MyCounterComponent));
counterComponentRef.setInput('count', counterSignal);

Alternatives considered

I see there may be a problem with the auto-detection of signals in the setInput method, when the input requires a signal. That's why I would suggest a config flag or separate method.

counterComponentRef.setInput(counterSignal, { useSignal: true })
counterComponentRef.setInputBySignal(counterSignal)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions