Skip to content

Feature: add method to change inputs in ComponentRef #22567

Closed

Description

@dawidgarus

I'm submitting a...


[ ] Regression (a behavior that used to work and stopped working in a new release)
[ ] Bug report  
[x] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question

Current behavior

To change inputs of component creates via ComponentFactory we need to access component instance directly, like that:

componentRef.instance.myInput = 'new value';

Expected behavior

There should exist a method on ComponentFactory that changes inputs, for example:

componentRef.changeInputs({ myInput: 'new value' });

Minimal reproduction of the problem with instructions

N/A

What is the motivation / use case for changing the behavior?

Changing properties on component instance won't call ngOnChanges. You have to do it manually, and that's really annoying because You really can't assume that it's not necessary for component to work correctly.
Calling changeInputs should also call ngOnChanges on component instance. It's also might be a good idea to delay it until change detection is triggered or trigger change detection automatically when changeInputs is called, so ngOnChanges would be called only once before ngDoCheck. Again, some components may rely on ngOnChanges being followed by ngDoCheck.

Activity

  1. devoto13 commented on Mar 3, 2018

    @devoto13
    Contributor

    This is a very cool idea. It should also allow to test OnPush components without adding a wrapper component, so should at least partially resolve #12313.

  2. added this to the needsTriage milestone on Mar 5, 2018
  3. added
    featureLabel used to distinguish feature request from other issues
    on Mar 29, 2018
  4. modified the milestones: needsTriage, Backlog on Mar 29, 2018
  5. angular-robot commented on Jun 4, 2021

    @angular-robot
    Contributor

    Just a heads up that we kicked off a community voting process for your feature request. There are 20 days until the voting process ends.

    Find more details about Angular's feature request process in our documentation.

  6. added
    feature: under considerationFeature request for which voting has completed and the request is now under consideration
    on Jun 5, 2021
  7. vzakharov-rxnt commented on May 3, 2022

    @vzakharov-rxnt

    Is it still being considered? I think it would be a very useful feature.

  8. angular-automatic-lock-bot commented on Aug 1, 2022

    @angular-automatic-lock-bot

    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.

  9. locked and limited conversation to collaborators on Aug 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions