-
Notifications
You must be signed in to change notification settings - Fork 3k
Use Deep merge rather then extend when Inheriting Data Properties on Nested views #3045
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
Comments
We used to do For this reason, I don't think we can switch back to the "copy" approach. I'm curious what problems you're experiencing with the current prototypal inherit approach? |
sure. given this code
In /services/vaccinations I would expect $state.current.data.meta to be
But it turns out to be
|
btw... I'm getting around the problem by doing this
I'm kinda assuming that this will only work with inheritence from the root view to the leaf view - and won't include anything inbetween. |
The ship has sailed on the decision between copying vs prototypal inheritance. Switching to deep copy would be a breaking change for many apps which expect a child state's data property to clobber a parent state's data property. If you want non-standard (deep copy) behavior you can certainly implement it for your app: $stateProvider.decorator('data', function(state, parentDecoratorFn) {
var parentData = state.parent && state.parent.data || {};
var selfData = state.self.data || {};
return state.self.data = angular.merge({}, parentData, selfData);
}); example: |
no worries, thanks for the example, thats really nice of you.. 👍 |
This seems to work for me ok, would really help when using Data to provide configurable properties for things like Meta data
The text was updated successfully, but these errors were encountered: