2

非常によく似た2つのAngularJSディレクティブがあるため、1つのコントローラーを使用して両方を処理したいと考えています。コントローラ コードで 2 つのディレクティブを区別するために、現在使用されているディレクティブを知りたいと考えています。私が言うことができる方法はありますか?AngularJS の些細な機能のように聞こえますが、これまでのところドキュメントで見つけることができません。

<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???
    }
);
4

1 に答える 1