When developing directives I separate all of the functionality from the 
directive.  Then the functional code can be combined into a common set of 
directive functions. 
Not strictly inheritance, but a nice way to develop business logic, then 
extend it into one or more directives. 

(function (angular, myDirectiveBase) {
    'use strict';
    var _config, // configuration settings

        //* Link the scope of this directive to it's events
        _link = function (scope, element, attributes) {
            angular.extend(scope, {
                //fields
                foo:0,
                // methods
                stuffClicked: function(value) {
                    myDirectiveBase.stuffHappensEventHandler(scope, value);
                }
            });
        },

        // Directive constructor
        _directive = function (service) {
            _config = service.config;
            return {
                template: "<div ng-click=\"stuffClicked()\">A really cool 
template<\/div>",
                restrict: 'E',
                replace: true,
                link: _link
            };
        };

    // define the injected modules for this directive
    _directive.$inject = [
        'someService'   // contains config settings for this directive
    ];
    // assign this as an angular directive
    
angular.module('SecurePortal').directive('reportingDashboardSummaryReports', 
_directive);
})(angular,myDirectiveBase);



On Sunday, January 12, 2014 5:08:45 PM UTC, Ben Greer wrote:
>
> I'm trying to figure out how one might extend functionality to all 
> directives, or at least all in a given module.
>
> I have one example use case, 'initialize an empty element of the same name 
> as the directive, to get around IE's weak html5 compatibility', but there 
> are many others.
>
>
> So far I've only come up with 2 ways to accomplish anything close to this:
>
> https://gist.github.com/wishfoundry/8387418
> https://gist.github.com/wishfoundry/8387308
>
> The first is quite hacky, and would not apply to module dependancies. The 
> second is less hacky but only selects one component.
>
> Is there a more angular way to do this, or this worth a feature request?
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to