javascript - How to access $scope from one controller to another in angular -


i have these controller codes different js files.

nlgoalsctrl.js

angular.module('mysite').controller('nlgoalsctrl', function ($scope) {     $scope.goals_selected = []; }); 

nlsessionsctrl.js

angular.module('mysite').controller('nlsessionsctrl', function ($scope) {     //access $scope.goals_selected here }); 

i need able access $scope.goals_selected nlsessionsctrl. how do this? guys.

use factory/service store goals responsible sharing data among controllers.

myapp.factory('myservice', [function() {         var goals = {};         return {             getgoals: function() {                 return goals             },              setgoals: function(op) {                 goals = op;             },         }     }])     .controller('nlgoalsctrl', [function($scope, myservice) {         $scope.goals_selected  = {};         //update goals_selected         myservice.setgoals($scope.goals_selected );     }])     .controller('nlsessionsctrl', [function($scope, myservice) {         //fetch         $scope.goals_selected  = myservice.getgoals();     }]); 

Comments

Popular posts from this blog

ruby - Trying to change last to "x"s to 23 -

jquery - Clone last and append item to closest class -

c - Unrecognised emulation mode: elf_i386 on MinGW32 -