javascript - AngularJS UI-Router: Two way binding between resolved object in child/parent state—Child state won't update -


i have parent state , child state. parent state resolves object. then, child state resolves object parent state.

because child state resolving object parent state, expect two-way binding occur. , oddly, although changes child state (i.e, adding property), update object in parent state—changes in object in parent state not affecting resolved object in child state, surprised me.

i know $broadcast changes in resolved object in parent state child state, understand why resolved object in child state not being updated automatically.

here's i'm working with. parent state:

.config(function($stateprovider) {   $stateprovider.state('parent', {     template:  ''     +'  <div>parent state</div>'     +'    <div>modify property on parent state, object.someproperty:'     +'      <input ng-model="object.someproperty">'     +'        {{object.someproperty}}'     +'    </div>'     +'  </div>'      +'  include child state'     +'  <ui-view></ui-view>',     controller: function($scope) {        $scope.object = object;      },     resolve: {        object: [function() {          var object = '';          object.someproperty = 'initialvalue';          return object;        }]     }   }) 

and child state:

  .state('parent.child', {     template: ''     +'  <div>child state</div>'     +'    <div>watch property parent state, object.someproperty'     +'        {{object.someproperty}}'     +'    </div>',     resolve: {       objectfromparent: ['object', function(object) {         return object;       }]     },     controller: function(objectfromparent) {        $scope.objectfromparent = objectfromparent;               }           }); }); 

does resolve in child state occur on instantiation? ie.—once child state resolves object parent state, no longer listening changes resolved object? doesn't seem should case.

plnkr might bugging out—my code won't work unknown reasons: http://plnkr.co/edit/ejv4ttsip6hpvmg0oanl?p=preview

any direction or insight appreciated. thank you!

all expectations correct. , there bit adjusted plunker working.

the important change making shared object real object (not string)

$stateprovider.state('parent', {     url: '/parent',     template:  ...,     controller: function($scope, object) {               $scope.object = object;            },     resolve: {        object: [function() {          //var object = '';          var object = {};          object.someproperty = 'initialvalue';          return object;        }]     } 

mostly lines:

//var object = ''; var object = {}; 

this way, $scope.object becomes reference object. means, parent , child share reference object. , in deed - if change (add property, change property) - know change... because share reference 1 object

check here


Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -