I have two directives and a controller, the problem is that i can't call a function 'addMarkers()' of the controller from my directive .
i have the following codes:
derectives.js
app .directive('collection', function () { var tpl = '<ul><member ng-repeat="member in collection" member="member"></member></ul>'; return { restrict: "E", replace: true, scope: { collection: '=' }, template: tpl } }) app .directive('member', function ($compile) { var tpl = '<li><a ng-click="addMarkers(member)" >{{member.title}}</a>'+ '<input class="align" ng-if="!member.children" type="checkbox" ng-checked="true"/></li>'; return { restrict: "E", replace: true, scope: { member: '=' }, template: tpl, link: function (scope, element, attrs) { if (angular.isArray(scope.member.children)) { element.append("<collection collection='member.children'></collection>"); $compile(element.contents())(scope) } } } }) controller.js
app .controller('IndexCtrl', function($scope, itemProvider){ itemProvider.getItems().success(function(data){ $scope.items = data; }); $scope.addMarkers = function(item){ alert("Helloo"); $scope.markers = itemProvider.addMarkers(); } }); index.html
<div id="menu" ng-controller="IndexCtrl"> <nav> <h2><i class="fa fa-reorder"></i>All Categories</h2> <collection collection='items'></collection> </nav> </div>