I have 2 AngularJS Directives which are very similar, so i want to use one single controller to handle both of them. In order to differentiate in the Controller code between the 2 directives, I want to be able to know which directive is currently being used. Is there a way i can tell? it sounds like a trivial function in AngularJS, but i can't find it in the docs so far.
<div dirA ></div>
<div dirB'></div>
app.directive('dirA', function() {
return {
restrict: 'A',
replace: true,
controller: 'CommonCtrl',
};
});
app.directive('dirB', function() {
return {
restrict: 'A',
replace: true,
controller: 'CommonCtrl',
};
});
app.controller('CommonCtrl',
function CommonCtrl($scope, $location, $log, $attrs) {
// how do i know which directive is using me now???
}
);