Call into another directive
From one directive (droppable), make a call directly into another directive (Dashboard)
by bob m
HTML
<div ng-app="app">
<div dashboard>
<button id="dash" droppable ng-click="handleDrop('TEST', $event)">Handle Drop</button>
</div>
</div>
JavaScript
var app = angular.module('app',
[
]);
app.directive('droppable', [function () {
return {
restrict: 'A',
require: '^?dashboard',
link: function (scope, elem, attrs, dashboardCtrl) {
scope.handleDrop = function(param, $event) {
dashboardCtrl.addWidgetInternal(param, $event);
}
}
}
}]);
app.directive('dashboard', [function () {
return {
restrict: 'A',
controller: function ($scope) {
this.addWidgetInternal = function(param, $event) {
console.log(param, $event);
}
}
}
}]);