Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support InputSignal for ComponentRef #54166

Closed
Celtian opened this issue Jan 30, 2024 · 2 comments
Closed

Support InputSignal for ComponentRef #54166

Celtian opened this issue Jan 30, 2024 · 2 comments

Comments

@Celtian
Copy link

Celtian commented Jan 30, 2024

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

No response

Description

Right now I am probably unable to pass InputSignal via ComponentRef

@Component({
  ...
})
export class TooltipComponent {
  public text = input.required<string>();
}

@Directive({
  selector: '[appTooltip]',
  standalone: true,
})
export class TooltipDirective {
  private overlay = inject(Overlay);

  private overlayRef = this.overlay.create({
    // positionStrategy: this.positionStrategy(),
  });

  public tooltipText = input.required<string>();

  @HostListener('mouseenter')
  public show(): void {
    const tooltipPortal = new ComponentPortal(TooltipComponent);
    const tooltipRef: ComponentRef<TooltipComponent> = this.overlayRef.attach(tooltipPortal);
    tooltipRef.instance.text = this.tooltipText; // <-- this is not working
  }
}

Proposed solution

This line should be working

tooltipRef.instance.text = this.tooltipText; 

Alternatives considered

Or it should work like

tooltipRef.instance.text = this.tooltipText(); 
@atscott
Copy link
Contributor

atscott commented Jan 30, 2024

This is expected. You should use ComponentRef.setInput instead. Directly assigning values in this way sidesteps the features of inputs (such as ngOnChanges or notifying Angular that change detection needs to run)

@atscott atscott closed this as completed Jan 30, 2024
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Mar 1, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants