Skip to content

Add a mechanism to reload a component #51302

Closed as not planned
Closed as not planned

Description

@darius-iko

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

core

Description

App.component.html:
<div><child-component></child-component></div>

Add a mechanism to reload child component in app component so that the child component can be recreated and go through the initial lifecycle.

Proposed solution

  1. By adding ViewChild to refer to the child component and call ParentComponent.reloadView(childComponent).
  2. By adding a key to the child component. If the key is changed, then the component will be auto-reload like the one in React.

Activity

  1. added
    needs: clarification
    feature
    on Aug 9, 2023
  2. alxhub commented on Aug 9, 2023

    @alxhub
    Member

    Hi @darius-iko,

    Can you give some detail on what problem(s) or use cases you would expect this feature to address?

  3. darius-iko commented on Aug 9, 2023

    @darius-iko
    Author

    Hi @alxhub

    Sometimes the child component from a third-party library initializes the view information in the OnInit or AfterViewInit or constructor, and the changes to the value of the model binding to the component are not reflected directly in the view, and because of that, we need to reload the component to make it reflected.

  4. darius-iko commented on Aug 9, 2023

    @darius-iko
    Author

    Sometimes when the main component is very complicated (contains filter and sort form, table and pagination, etc, or nested components), then to reset the main component, we have to reset everything in the main component one by one. It is just more efficient if we just reload the main component, and the state will automatically get reset.

  5. mlc-mlapis commented on Aug 9, 2023

    @mlc-mlapis
    Contributor

    @darius-iko It seems all the reasons imply only solving problems in the conceptual design of an application or third-party components.

  6. darius-iko commented on Aug 9, 2023

    @darius-iko
    Author

    For third-party components, it will take years for them to fix it to allow handling for any model changes. So the only workaround is to refresh the component.

  7. angular-robot commented on Aug 9, 2023

    @angular-robot
    Contributor

    This feature request is now candidate for our backlog! In the next phase, the community has 60 days to upvote. If the request receives more than 20 upvotes, we'll move it to our consideration list.

    You can find more details about the feature request process in our documentation.

  8. pkozlowski-opensource commented on Aug 10, 2023

    @pkozlowski-opensource
    Member

    For third-party components, it will take years for them to fix it to allow handling for any model changes.

    Some of the projects are well maintained and pretty responsive so I would suggest opening issues on the relevant projects. And considering alternatives for ones that don't work correctly and / or are not well maintained.

    So the only workaround is to refresh the component.

    I don't think we want to build such workarounds into the framework. You can always inject ChangeDetectorRef and call detectChanges on it to refresh a given component and all its children - the work-around exists but again, this is not the solution for questionable design.

  9. angular-automatic-lock-bot commented on Sep 10, 2023

    @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.

  10. locked and limited conversation to collaborators on Sep 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    featureneeds: clarification

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions