I currently am defining some directives programmatically from an array of values ( directiveNames in this example)

var directiveNames = ['foo', 'bar']; directiveNames.forEach(function(name) { angular .module('myModule') .directive(name, buildDirective(name)); }); function buildDirective(name) { return function() { return { restrict: 'E', template: '<p>' + name + '</p>' }; }; }

I now want to reuse this array elsewhere.

angular .module('myModule') .constant('directiveNames', ['foo', 'bar']);

The problem is, I do not know how I can inject this constant into the above snippet. I've tried wrapping the code in a module.config and a module.run block, but this does not seem to work.

Is this possible? If so how?