🚀[FEATURE]: Add support for dynamic ngxsForm
path
#1904
Unanswered
Andreas-Hjortland
asked this question in
Ideas
Replies: 2 comments 1 reply
-
Thank you for the suggestion. I think that there is some merit in this request, but we need to make sure that it has general, and reasonable application, as well as no negative side effects for the regular use cases. |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Relevant Package
This feature request is for @ngxs/form-pluginDescription
When I change the
[ngxsForm]
property on the directive dynamically, it does not change the listeners on the store to reflect my changes.Describe the problem you are trying to solve
I have an app with multiple tabs with forms which I would like to allow the user to jump between without saving (for instance to cross reference another entry before saving). When the user jumps to another tab the form is not updated because the form plugin is still bound to the old form since angular reuses my components and the `ngxsForm` directive only use the initial value of the path.I have created a small project to illustrate the problem here. If you navigate to Superman and then to Batman, the form is still showing the values from the superman route. I have added the devtool plugin so if you open the app in a new window, you can see how the form plugin is a bit confused with where in the state it should read and write the form values after the initial load.
Describe the solution you'd like
I would like the ngxs form directive to dynamically update it's listeners whenever we change the path property on the `ngxsForm` attribute.What I believe we have to do is to replace the
ngOnInit
method with anngOnChanges
method which is filtered on the path parameter and will unsubscribe the existing subscriptions whilst resubscribing with the new path whenever we change it.Describe alternatives you've considered
I havent tried this, but I think we could replace the RouteReuseStrategy of our app to never reuse the components when the users are navigating between the same components with different parameters, but I believe that to be a sub-optimal solution since we are then opting out of some otherwise great performance and accessibility features like keeping the scroll position and other browser state when a user is navigating between entities of the same type.If you would like, I can try to create a pull request with my proposed solution, and if you have some feedback on my proposal I can try to incorporate that as well =)
Beta Was this translation helpful? Give feedback.
All reactions