Solvedui router $onChanges does not trigger for 1-way binded resolved data
✔️Accepted Answer
I founded another, much more better solution for that issue:). Or, I think I found..
component conf:
app.component('grandChildComponent', {
bindings: {
name: '<',
onEvent: '&'
},
In ui-router conf:
.state('grandchild', {
url: "/grandchild",
template: '<grand-child-component name="$ctrl.nameForGrandChild" on-event="$ctrl.fireEvent()"></grand-child-component>',
});
There is no use component: prop from newest ui-router.
There are bindings name, and onEvent. grandChild is stateless/dumb component, which get his bindings through ui-router conf in template prop in object configuration.
-onEvent binding can be fired in child stateless, and parent statefull component catch it.
-name is passed down from parent statefull to stateless child
-when binding name is changed in parent, then is changed in child also.
-$onChange() in child will be fired when binding will be changed in parent.
Other Answers:
Thanks! I thinking would be pretty cool if we could set a flag on a state or on a view to say something like rebindable: true or an option in state.go to say "rebind my resolves but do not reinitialize the component"
It seems that it is the fact that resolved bindings are 1-time binded and not 1-way binded that prevents the $onChanges hook to be invoked in the component when the resolved object is reassigned.
Should it be considered as a bug?
Would it be possible to do 1-way binding with the resolved properties?
In the following example (also available in this plunker), I was expecting the $onChanges hook to be triggered when the object that is resolved for the consumer component is reassigned by the editor component but it does not. When using the modify method, the modifications are visible because 1-way binding is done by reference, but ideally, the consumer component would do a local clone of the object in the $onChanges hook so as to avoid any unwanted side-effect (like the component modifying the object).
Could someone explain me what is happening here ?
This second plunker is the same example, but using a service instead of a global variable.
For the record, I have set up a StackOverflow question on the subject.