有没有办法检测哪个指令在控制器中调用一个函数而不从指令本身传递任何参数。
演示我需要的简单示例:
控制器:
app.controller('mainCtrl', function ($scope) {
// detect the directive calling the displayDirective function.
var detectedDirective = ""; // <--
$scope.displayDirective = function (message) {
alert(message + detectedDirective );
}
}
)
指令:
app.directive('directive1', function () {
return {
restrict: 'A',
scope: {
update: "&"
},
link: function (scope, ele, attrs) {
scope.update({message: "I am"});
}
}})
app.directive('directive2', function () {
return {
restrict: 'A',
scope: {
update: "&"
},
link: function (scope, ele, attrs) {
scope.update({message: "I am"});
}
}})
for plnkr