There is a common function in my cornector. I have several controllers that use the same function.
I need to change the Scope variable from the Rootscope function.
http://jsfiddle.net/qkZHG/
In js
angular.module('myApp', [])
.run(function($rootScope) {
$rootScope.rs = new Date();
$rootScope.changeRsFromRs = function() {
$rootScope.rs = new Date();
};
$rootScope.changeSFromRs = function() {
$scope.s = new Date();
};
})
.controller('myCtrl', function($scope, $rootScope) {
$scope.s = new Date();
$scope.changeSFromS = function() {
$scope.s = new Date();
};
$scope.changeRsFromS = function() {
$rootScope.rs = new Date();
};
});
In html,
<button class="not-working" ng-click='changeSFromRs()'>Change Scope value from Rootscope</button>
source
share