title: How to get Values from Other AngularJs Controller $scope variable
body: <p>I'm having two controllers namely <strong>AController</strong> and <strong>BController</strong>.</p>
  
  <p>I need to get the value of Controller <strong>AController</strong>'s $scope.myName to the Controller <strong>BController</strong>'s $scope.myName.</p>
  
  <blockquote>
    <p>Note: Here I'm not passing the value, I'm trying to fetch the values.</p>
  </blockquote>
  
  <p>My Sample AngularJS Script</p>
  
  <pre><code>var app = angular.module("DemoProject", ['ngRoute', 'ngAnimate', 'ngMessages', 'ngMaterial']);
  
  app.controller('AController', function ($scope, $location, $rootScope, $document, $window) {
      $scope.myName = 'Bala';
  });
  
  app.controller('BController', function ($scope, $location, $rootScope, $document, $window) {
      $scope.myName = AController.$scope.myName;
  });
  </code></pre>
  
  <p>Broadcast and other functionalities are for passing the values. I think not for fetching the values. Kindly assist me.</p>
  
  <blockquote>
    <p>Note: Don't pass the value form <strong>AController</strong>. I need a solution how
    to fetch. Kindly assist me.</p>
  </blockquote>
  
  <hr>
  
  <p>Difference Between my Post <strong>How to get Values from Other AngularJs Controller $scope variable</strong> and <a href="https://stackoverflow.com/questions/11938380/global-variables-in-angularjs">Global variables in AngularJS</a></p>
  
  <p><strong>The Content of the Post is</strong></p>
  
  <p>I have a problem where i'm initialising a variable on the scope in a controller. Then it gets changed in another controller when a user logs in. This variable is used to control things such as the navigation bar and restricts access to parts of the site depending on the type of user, so its important that it holds its value. The problem with it is that the controller that initialises it, gets called again by angular some how and then resets the variable back to its initial value.</p>
  
  <p>I assume this is not the correct way of declaring and initialising global variables, well its not really global, so my question is what is the correct way and is there any good examples around that work with the current version of angular?</p>
  
  <p><strong>Explanation : How my Post Differ from the said Post</strong></p>
  
  <p>Kindly see the sentence "<strong>Value changed in another controller when a user logs</strong>", it means assume the Controller B tried to pass a value via <strong>Broadcast</strong> to Controller A to set the <code>$scope.myName</code>.</p>
  
  <p>Here, my requirement is how to get the value or how to fetch the value of $scope.myName from AController within BController.</p>
  
  <p>First understand the post, then mark it as Duplicate.</p>