$scope usage

<div ng-controller="CtrlOne">
{{VARIABLE_ONE}}
</div>

<div ng-controller="CtrlTwo">
{{VARIABLE_TWO}}
</div>

.controller("CtrlOne", function($scope){
$scope.VARIABLE_ONE = "ONE";
})

.controller("CtrlTwo", function($scope){
$scope.VARIABLE_ONE = "1";
$scope.VARIABLE_TWO = "2";
})

How can i set $scope.VARIABLE_ONE = “1” from CtrlTwo ?? The above code is not working. Any help will be appreciated.

I think that VARIABLE_ONE must be a global variable or you pass variable to controller.

you have few solutions, eg:

  1. use $rootScope
  2. add third controller which will create parent scope for existing
  3. use events to communication between controllers

details how you can do it, you find here:
https://docs.angularjs.org/guide/scope

Thank you guys. $rootScope solved my problem.

Hi, Could you put how solved?

<div ng-controller="CtrlOne">
{{VARIABLE_ONE}}
</div>

<div ng-controller="CtrlTwo">
{{VARIABLE_TWO}}
</div>

.controller("CtrlOne", function($scope){
$scope.VARIABLE_ONE = "ONE";
})

.controller("CtrlTwo", function($scope, **$rootScope**){
**$rootScope.VARIABLE_ONE = "1";**
$scope.VARIABLE_TWO = "2";
})
1 Like