Controller scope inside Directive with Angular I decided to write a simple runnable example to try and express my concern:

index.html

&lt;section ng-app="App" ng-clock&gt;
  &lt;div ng-controller="ShopController as shop"&gt;                
      &lt;prize-directive ng-repeat="prize in prizes"&gt;&lt;/prize-directive&gt;
  &lt;/div&gt;
&lt;/section&gt;


Inside my shopController I have set a static prize list just for the purpose of keeping it simple.

ShopController.js

angular.module('app.controllers').controller('ShopController',
   ['PrizeService', '$scope', function (PrizeService, $scope) {

    $scope.prizes = [
      {name: 'First Prize', cost: 10, 
         image: 'upload/prize/image1.png', note: 'This is a note'},
      {name: 'Second Prize', cost: 20,
         image: 'upload/prize/image2.png', note: 'This is a note'},
      {name: 'Third Prize', cost: 30, 
         image: 'upload/prize/image3.png', note: 'This is a note'}
    ];

    $scope.reclaim = function (prize) {
      console.log(prize);
    };
}]);


In the original code I use the PrizeService to load a list of available prizes, but back to my main problem:

PrizeDirective

angular.module('app.directives').directive('prizeDirective', function () {
  return {    
    restrict: 'E',
    templateUrl: 'js/directives/PrizeDirective.html'
  };
});


HTML:

&lt;div&gt;    
    &lt;img ng-src="{{Endpoint + prize.image}}" /&gt;
    &lt;h3&gt;{{prize.name}}&lt;/h3&gt;
    &lt;span&gt;Pontos: {{prize.cost}}&lt;/span&gt;    
    &lt;p&gt;{{prize.note}}&lt;/p&gt;
&lt;/div&gt;
&lt;reclaim-directive&gt;&lt;/reclaim-directive&gt;


Here in the HTML portion of the directive, I'm using a variable name that was defined in the index.html. Although it bothers me, I'm willing to let it go because the variable name was defined inside the ng-repeat code, which is inside the prize-directive directive. But when we go to the reclaim-directive, things get a little bit more heated:

angular.module('app.directives').directive('reclaimDirective', function () {
  return {    
    restrict: 'E',
    template: '&lt;button ng-click="reclaim(prize)"&gt;Resgatar&lt;/button&gt;'
  };
});


Note: I'm actually using the templateUrl here, but again, I'm simplifying it just to show my point.

Now I'm using a function name defined inside ShopController in the Reclaim Directive. Differently from OOP, this is not really an inheritance of an abstract method which even the IDE can tell you that something is wrong and, to me, it seems like a bad practice. 

I would love to hear people's thoughts on this approach and if there is anything that I'm missing that could help clean up this code.
Now I'm using a function name defined inside ShopController in the Reclaim Directive... it seems like a bad practice.


Yep, this kind of code will be hard to debug and maintain.


You're depending on the existence of reclaim to be somewhere in the scope chain, on some controller enclosing your directive.
There's no indication whenever you use the directive that reclaim is missing in the scope. The directive will fail only if you click it.
Without proper tools like Batarang, in a highly nested controller structure, reclaim will be hard to find when you don't know which controller it resides.


If &lt;reclaim-directive&gt; isn't that huge, and is not used anywhere else independently, then it's contents should belong to &lt;prize-directive&gt;.

If &lt;reclaim-directive&gt; is big and independent enough to be a separate directive, then consider making it a sibling of &lt;reclaim-directive&gt;. That way, you avoid the extra nested level:

&lt;div ng-controller="ShopController as shop"&gt;                
  &lt;prize-directive ng-repeat="prize in prizes"&gt;&lt;/prize-directive&gt;
  &lt;reclaim-directive&gt;&lt;/reclaim-directive&gt;
&lt;/div&gt;


Most importantly, instead of depending on implicit existence of reclaim in the scope, why not provide it to the directive explicitly? Construct a scope for the directive, which accepts a binding of reclaim. I believe this is the way to do it:

&lt;prize-directive ng-repeat="prize in prizes" on-reclaim="reclaim"&gt;&lt;/prize-directive&gt;

angular.module('app.directives').directive('prizeDirective', function () {
  return {
    restrict: 'E',
    templateUrl: 'js/directives/PrizeDirective.html',
    scope: {
      onReclaim: '='
    }
  };
});

&lt;!-- onReclaim assigned to on-reclaim comes from the prizeDirective --&gt;
&lt;reclaim-directive on-reclaim="onReclaim"&gt;&lt;/reclaim-directive&gt;

angular.module('app.directives').directive('reclaimDirective', function () {
  return {    
    restrict: 'E',
    template: '&lt;button ng-click="onReclaim(prize)"&gt;Resgatar&lt;/button&gt;',
    scope: {
      onReclaim: '='
    }
  };
});