Reputation: 4062
I am trying to trigger test()
using ng-click
but it's not working. The test()
function works with ng-click
elsewhere though, so I am assuming that it has to do with the fact that it is an ng-repeat
ed directive.
How do I fix this?
Upvotes: 2
Views: 768
Reputation: 136134
Your directive is using isolated
scope, so it don't have access to it parent scope.
You need to pass the method to directive from its isolated scope using &
<div ng-repeat="day in thisMonth track by $index">
<drop-target index="$index" day="day" method="test()"></drop-target>
</div>
Directive
angular.module('app.directives.dropTarget', [])
.directive('dropTarget', function() {
return {
restrict: 'E',
scope: {
day: '=',
index: '=',
method: '&'
},
templateUrl: "calDay.html",
controller: function($scope) {
// not sure what this is
}
};
});
Directive template
<div class="dayExercise" ng-repeat="item in day.array" ng-click="method()">
{{item}}
</div>
Upvotes: 2
Reputation: 2365
You need to defint the "test" function in directive's controller (right where you wrote "//don't know what is this")
Upvotes: 1
Reputation: 716
Updated: http://plnkr.co/edit/mKnX6qpxQBy20JMssWHa?p=preview
scope: {
day: '=',
index : '=',
funcOnClick: '&'
}
Your problem is a $scope problem. You have to pass the function to your directive.
Upvotes: 0