I have a directive which inherits its scope from a controller. This Directive has a few methods, when I try to call these methods from the Parent Controller it says method undefined.
Parent Controller:
app.controller('ParentController', ['$scope', function($scope){
$scope.items = []; //Array of Objects.
$scope.someMethod = function(item){
$scope.directiveMethod(item.id);
}
}]);
Directive:
app.directive('someDirective', function(){
return {
restrict: 'A',
link: function(scope, el, attrs){
scope.tableGreen = function(id){
var element = angular.element('[data-cell='+id+']')
element.removeClass('some-class')
element.addClass('new-class')
}
}
}
})
HTML:
<div ng-controller="ParentController">
<div ng-repeat="item in items">
<button ng-click="someMethod(item)" >Green</button>
</div>
<div ng-include="/path/to/some/place">
<div class="some-class" some-directive></div>
</div>
</div>
Is this a right approach? Or is there a better way?