AngularJS Directive $scope is undefined -


i have following directive. when trigger open function , debugger error message in console says uncaught referenceerror: $scope not defined(…).

how possible $scope.open called when $scope undefined?

app.directive('photo', ['$http', 'modal', function($http, modal) {     return {         replace: true,         templateurl: '/assets/photo.html',         transclude: false,         scope: {             result: '=',             index: '@'         },         controller: ['$scope', '$http', 'modal', function($scope, $http, modal) {             $scope.prev = $scope.index - 1;             $scope.open = function() {                 debugger;             };         }]     } }]); 

here dom:

<div ng-repeat="r in results" photo result="r" index="$index"></div> 

if insert console.log($scope) before open function, , again right before debugger in function, following results. left before open called, right after open called. enter image description here

you inject $http , modal in directive definition (as did), no need in controller function, do:

controller: function($scope) {         $scope.prev = $scope.index - 1;         $scope.open = function() {             debugger;         };     } 

Comments