In my angularjs, i have two controllers and use the variable which is referred in UI. From UI I am calling method OpenPage of NumTwoController which updates value of variable1 and NumOneController tries to access updated value.
After I update the variable in NumTwoController, newly updated value is not reflecting in NumOneController and also in NumOne.html page.
myModule.controller('NumOneController', ['$rootScope', '$scope',
function ($rootScope, $scope) {
$scope.variable1 = 1; // initial value assigned
$scope.$on('NumOne', function (e, opt) {
var valueselected = $scope.variable1; //still 1 is assigned.trying to read the value assigned in NumTwoController
});
}
]);
myModule.controller('NumTwoController', ['$rootScope', '$scope',
function ($rootScope, $scope) {
$scope.variable1 = [];
$scope.OpenPage = function (menuItem, PageReload){
$scope.variable1 = 2;
});
}
]);
I tried adding $scope.$apply() but didnt succeed.
Guidance to reflect the updated value in the another controller is much appreciated