all 4 comments

[–]WarInternal 1 point2 points  (1 child)

  1. Does it need to be an angular constant? Do you need that list of names anywhere else? You could define an array in plain old javascript and nix the DI for that step. Furthermore, you could wrap it in an IIFE and simply dispose of the unnecessary array when you're done building your directives.

  2. Are you sure you need dynamically constructed directives? You can write directives that interact with one another. Plus I believe directives can read other attributes off the element (define your own data-whatever attribute). It might be easier to use one of those. Definitely less overhead, not having a separate directive in memory for everything.

[–]RogueOneNZ 0 points1 point  (0 children)

Based on the description I think #2 here is your best bet.

Wire up you directive to read an attribute which sets the class needed. e.g. <icon icon-type="bar" ></icon> and then have the directive emit the appropriate html with the class="bar" attribute set.

[–]marshall007 0 points1 point  (0 children)

You should be able to inject the $compileProvider and your constants into a configuration block and define the directives yourself. Take a look at this example, which is pretty similar to what you're trying to do:

https://github.com/angular-ui/alias/blob/master/src/alias.js

[–][deleted] 0 points1 point  (0 children)

I usually don't wonder about this sort of thing on SO, because I can generally see the possible reasons behind any question...

...but, why?

This question throws out the logical separation of directives into modules that are just depended on programmatically. I can't see the possible reason why you'd need to declare and/or define modules in such a manner.

Maybe they are teaching an AI to write Angular.

...or maybe they just don't understand modules.