javascript - Handling Scope between controllers -


ok, pretty new angular...figuring things out...and have run funky issue.

so have 1 controller (x) add/update/delete of simple objects.

i have controller (y) pretty darn simple, separate x. in controller i...err control...a header has dropdown of x in visible on every page.

my question is...if manipulate x..i.e. add another, want refresh dropdown lives in controller y. have handy refresh method in controller x, when gets called updates several different scope variables.

i have tried having service shared between x & y, scope stuff getting in way. can tell services don't $scope because can called multiple different controllers , scope gets messy.

what missing?

if need global variable, can put in $rootscope:

app.controller('xctrl', ['$scope', '$rootscope', function ($scope, $rootscope) {     $scope.init = function(){         .......         $rootscope.globalvar = ......;         .......     }     $scope.change = function(){         .......         $rootscope.globalvar = ......;         .......     } }]);  app.controller('yctrl', ['$scope', '$rootscope', function ($scope, $rootscope) {     $scope.use = function(){         .......         $scope.localvar = $rootscope.globalvar;         .......     } }]); 

Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -