Angular.js Inheritance of a directory controller

Suppose I have a directive:

.directive('money', ['Service', function (Service) {
/*
* Some code
*/
controller: ['$scope', '$element', '$attrs', '$parse', function (scope, cElement, attrs, $parse) {
    scope.someValue=1;
    scope.someFunction = function(){
        console.writeline('money');
    }
}

and there is a second directive:

 .directive('cash', ['Service', function (Service) {
    /*
    * Some code
    */
    controller: ['$scope', '$element', '$attrs', '$parse', function (scope, cElement, attrs, $parse) {
        scope.someValue=1;
        scope.someFunction = function(){
            console.writeline('cash');
        }
    }

As you can see, the only difference between the two directives is the content of one function. Thus, the ideal way would be to inherit the entire controller and shadow so thatsomeFunction

Is it possible to do something similar in angular, or should I leave two directives with such small differences?

+4
source share
2 answers

Why not just have a directive consolethat captures what to write from an attribute of a directive element?

So, instead of <div data-money></div>and <div data-cash></div>you will have <div data-console text="money"></div>and <div data-console text="cash"></div>.

, , , .


, ? , .

, , , ( ) . , , .

+1

, . : AngularJS

: , , .

0

All Articles