我有一个名为的指令<popup>
,其中包含许多<popup-link>
-directives。单击a 时,应通过调用其控制器上的函数来关闭<popup-link>
父指令。<popup>
close()
出于某种原因,我无法获取 的控制器实例<popup>
,因为它没有正确注入到 的链接功能<popup-link>
我收到以下错误,检查对象会产生instantiate.c吗?
对象 [对象对象] 没有方法“关闭”
我究竟做错了什么?
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();
}
);
}
}
});
和 HTML
<popup name="menuNavigator">
<popup-link ng-repeat="category in getCategories()" title="{{ category.Title }}" ng-click="navigateMenu($index)"></popup-link>
</popup>
谢谢!