I have a directive called <popup>
that contains a number of <popup-link>
-directives. When a <popup-link>
is clicked, the parent <popup>
directive should be closed by invoking a function close()
on its controller.
For some reason I cannot get the controller instance of <popup>
, as it is not injected correctly to the link function of <popup-link>
I get the below error and the inspecting the object yields instantiate.c ?
Object [object Object] has no method 'close'
What am I doing wrong?
directive('popup', function () {
return {
restrict: 'EA',
replace: true,
transclude: true,
template: '<div id="{{ popupId }}" class="navigatorPopup" ng-transclude></div>',
controller: function ($scope) {
$scope.close = function () {
//close popup
};
},
link: function (scope, element, attr) {
//
}
}
}).
directive('popupLink', function () {
return {
restrict: 'EA',
require: '^popup',
template: '<h3 ng-bind="title"></h3>',
replace: true,
scope: {
title: '@',
ngClick: '&'
},
link: function (scope, element, attr, popupCtrl) {
scope.popupCtrl = popupCtrl;
element.bind('click',
function () {
scope.popupCtrl.close();
scope.ngClick();
}
);
}
}
});
And the HTML
<popup name="menuNavigator">
<popup-link ng-repeat="category in getCategories()" title="{{ category.Title }}" ng-click="navigateMenu($index)"></popup-link>
</popup>
Thanks!