title: Access AngularJs directive variable inside controller
body: <p>I'm little bit new to Angularjs. What I want is access "<strong>$scope.myVar</strong>" variable inside '<strong>myController</strong>' controller. It would be great help if you can provide a solution. </p>
  
  <p><div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>angular.module('myDirective', [])
          .controller('myController', ['$scope', function ($scope) {
                 
              }])
          .directive('myDirective', function () {           
              return {
                  scope: {
                      myVar: '='                  
                  },
                  controller: function ($scope) {  
                      $scope.myVar = 'xyz';
                      alert($scope.myVar);
                  }
              };
          });</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;html lang="en-US"&gt;  
      &lt;script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"&gt;&lt;/script&gt;
      &lt;script type="text/javascript" src="newjavascript.js"&gt;&lt;/script&gt;
      &lt;body ng-app="myDirective"&gt;   
          &lt;div ng-controller="myController"&gt;
              &lt;my-directive&gt;&lt;/my-directive&gt;&gt;
          &lt;/div&gt;
      &lt;/body&gt;
  &lt;/html&gt; </code></pre>
  </div>
  </div>
  </p>