title: Using "this" instead of "scope" with AngularJS controllers and directives
body: <p>I was recently reading John Papa's opinionated <a href="https://github.com/johnpapa/angularjs-styleguide#single-responsibility" rel="noreferrer">AngularJS style guide</a> and noticed his convention on controllers:</p>
  
  <pre><code>/* recommended */
  function Customer () {
    var vm = this;
    vm.name = {};
    vm.sendMessage = function () { };
  }
  </code></pre>
  
  <p>When this is used in a controller it works just fine as you can do something like this (his example): </p>
  
  <pre><code>&lt;!-- recommended --&gt;
  &lt;div ng-controller="Customer as customer"&gt;
      {{ customer.name }}
  &lt;/div&gt;
  </code></pre>
  
  <p>However I am more curious in how it works with directives that rely on this controller. For example, using <code>$scope</code> on my controller I can do something like this:</p>
  
  <pre><code>testModule.directive("example", function(){
      return{
          template: "Hello {{customer}}",
          controller: "exampleCtrl"
      }
  });
  testModule.controller("exampleCtrl", exampleCtrl);
  function exampleCtrl($scope){
      $scope.message = "Display this";
  }
  </code></pre>
  
  <p>But I can't do this using <code>this.message</code>:</p>
  
  <pre><code>testModule.directive("example", function(){
      return{
          template: "Hello {{customer}}", //Doesn't work!
          controller: "exampleCtrl"
      }
  });
  testModule.controller("exampleCtrl", exampleCtrl);
  function exampleCtrl(){
      var vm = this;
      vm.message = "Display this";
  }
  </code></pre>
  
  <p>So my question is, how <em>would</em> this work in the directive? I've tried using:</p>
  
  <pre><code>{{customer}}
  {{this.customer}}
  {{exampleCtrl.customer}}
  </code></pre>
  
  <p>And none work. As you can see, I'm shooting in the dark and not really understanding the differences and how I could use <code>this</code> in Angular instead of <code>scope</code>. Also, as this isn't the convention, I haven't been able to find many resources speaking to it, since it's more a JS understanding thing than Angular.</p>
  
  <p>Any help is appreciated!</p>