title: AngularJS: Why and when people declare controller inside custom directives
body: <p>I have seen a couple of custom directives sample code and saw people declare controller inside custom directives. I am new in angular and that is why just do not understand when and why people declare controller inside custom directives?</p>
  
  <h2>here one usage</h2>
  
  <pre><code>app.directive('someDirective', function () {
    return {
      scope: {},
      controller: function () {
        this.name = 'Pascal'
      },
      controllerAs: 'ctrl',
      template: '&lt;div&gt;{{ctrl.name}}&lt;/div&gt;'
    };
  });
  </code></pre>
  
  <p>Code is taken from <a href="http://blog.thoughtram.io/angularjs/2015/01/02/exploring-angular-1.3-bindToController.html" rel="nofollow noreferrer">http://blog.thoughtram.io/angularjs/2015/01/02/exploring-angular-1.3-bindToController.html</a></p>
  
  <p>Also like to know what is the usage of <strong>bindToController: true,</strong>? what it does and when people use it.</p>
  
  <p>Please help me to understand this with a couple of example and code. I need to understand the importance of declaring controller inside custom directives.</p>
  
  <p>thanks</p>