When you set $scope data in a controller to affect the scope of other control, you can use $rootscope
As an example:
Set within a control a range
Mainapp.controller (' Menucontroller ', function ($scope, $rootScope) {
$rootScope. menus={}
$rootScope. Menus.showwelcome = false;
$rootScope. Menus.showexit = false;
$rootScope. Menus.activehome = "active";
$rootScope. Menus.activemystudy = "";
});
In another control B
Mainapp.controller (' HomeController ', function ($scope) {
$scope. Menus.activehome = "active";
$scope. Menus.activemystudy = "";
$scope. LoginForm = {userid: "Lee"};
$scope. Login = function () {
$scope. Menus.loginid = $scope. Loginform.userid;
$scope. Menus.showwelcome = true;
$scope. Menus.showexit = true;
}
});
When you manipulate the elements in B, the elements in a are affected. Note that if the data name in B is the same as in $rootscope, you need to use $rootscope when referencing in B.
The key factor is that all applications have a $rootScopethat can function in all of the HTML elements contained in the NG-APP directive.
$rootScope can act on the entire application. is the bridge of scope in each controller. Values defined with Rootscope can be used in each controller.
Angulajs how to share data between controllers