angularjs - Sharing ui-router 'custom data' between sibling states -
i thought possible, may wrong. child state, can share 'custom data' of parent state between 2 sibling states?
update: yes possible, there must wrong own code. here simplified example on plunker. historical reasons, rest of question continues below. note original code example had typo had chidl2
instead of child2
, why @originof used in answer.
here simplified example of trying do.
app.config(function ($stateprovider) { $stateprovider .state('parent', { abstract: true, template: '<div ui-view></div>' data: { sharedarray: [] } }) .state('parent.child1', { url: '/child1', controller: 'child1ctrl', templateurl: 'js/lib/parent/child1.tpl.html', }) .state('parent.child2', { url: '/child2/:id', controller: 'child2ctrl', templateurl: 'js/lib/records/parentitem.tpl.html' }); }); app.controller('child1ctrl', function ($state) { // loaded first $state.current.data.sharedarray.push("child 1 adding data data"); }); app.controller('child2ctrl', function ($state) { // loaded child1ctrl console.log($state.current.data.sharedarray); // says '[]' })
basically, want to:
- set array in parent, abstract state (
parent
); - transition child state (
parent.child1
) , update array; - transition second child state (
parent.child2
) , still have access update array.
currently, able view , change array inside parent.child1
, when transition parent.child2
, custom data, $state.current.data.sharedarray
, empty.
probably have modify parent.child12 parent.child1.child12.
if flow parent -> child1 -> child12 real angular flow parent -> child1, parent -> child12, in child12 sharedarray []
Comments
Post a Comment