2
votes

I am lazy loading modules dependent on the user. And then i wan't to declare a decorator for the directives being loaded with the module. But i am getting unknown provider when trying to decorate a directive.

angular.module(moduleName).config(function ($provide) {
    var invokeQueue = angular.module(moduleName)._invokeQueue;
    invokeQueue.forEach(function (service) {
        if(service[1] === 'directive'){
            var directive = service[2][0];
            $provide.decorator(directive, function ($delegate) {
                return $delegate;
            })
        }
    });
});

var directive is the directive name and is being set.

error

[$injector:unpr] Unknown provider: demoDirectiveProvider

If i change the code to take services or factories instead it works.

Both of the following works

if(service[1] === 'service')
if(service[1] === 'factory')

any suggestions to why this wan't work with directives

1

1 Answers

5
votes

turns out angular directive names is suffixed with with "Directive".

angular.module(moduleName).config(function ($provide) {
    var invokeQueue = angular.module(moduleName)._invokeQueue;
    invokeQueue.forEach(function (service) {
        if(service[1] === 'directive'){
            var directive = service[2][0];
            console.log(directive);
            $provide.decorator(directive+'Directive', function ($delegate) {
                return $delegate;
            })
        }
    });
});