I'm using 2 different controllers sharing a global value currentOpenningFolder. I want that 2 controllers can both sync to that variable no matter what. But in this example, in the GET request I change the variable in the first controller but I can't view that variable in the second controller. Instead it shows the initial value of currentOpenningFolder. Any ideas why this may be happening?
angular.module('scopeExample', [])
.controller('MyController', ['$scope','currentOpenningFolder','$http', function($scope,currentOpenningFolder,$http) {
$scope.sayHello = function() {
$http.get('https://api.github.com/users/chuson1996').then(function(obj){
currentOpenningFolder = obj;
console.log(currentOpenningFolder);
})
};
}])
.controller('MyController2', ['$scope','currentOpenningFolder', function($scope,currentOpenningFolder) {
$scope.sayHello = function() {
$scope.currentOpenningFolder = currentOpenningFolder;
console.log($scope.currentOpenningFolder);
};
}])
.value('currentOpenningFolder',{});