JSFiddle - React, Tailwind, and code Playground
HTML
<div ng-controller='mainCtrl'>
<foo></foo>
</div>
JavaScript
var app = angular.module('myApp', [])
app.controller('mainCtrl', function($scope) {
});
app.directive('foo',function() {
return {
restrict: 'E',
link: function(scope,iElement,iAttrs) {
scope.message = "directive message";
scope.alertFunction = function() {
alert("testing function");
}
},
template: "<div ng-click='alertFunction()'> this is the alert message : {{message}} </div>"
}
});
app.config( function( $provide ) {
$provide.decorator('fooDirective',function($delegate) {
var directive = $delegate[0];
var link = directive.link;
directive.compile = function() {
return function(scope, element, attrs) {
link.apply(this, arguments);
scope.alertFunction = function() {
alert(scope.message); // using directive message variable, but overriding the alertFunction method
}
}
}
return $delegate;
});
});