Closed OpenSiteMobile closed 7 years ago
If you can provide a PR with this change + tests, we can take a better look at what this means for compiling.
Closing since we haven't got any feedback from the OP. In addition, it is not exactly clear what the usecase is and the proposed fix will not work for directives with the same name (which is a perfectly valid usecase).
This is an informal feature request. The "addDirective" function under $CompileProvider -> "applyDirectivesToNode" doesn't check to see if the next directive being added, has already been previously added. And as far as I can tell, it doesn't seem to make a difference for the more typical running of AngularJS, with addtional modules all being loaded at page load. The directives apparently always get written to the same index anyway, so no bad things happen. So it isn't a bug or anything.
The problem arises when you load AngularJS style modules after page load. So dynamically loading some now standard modules will try to add the same directive twice (sometime via sub modules), and you get a "mutilple directive" error because of it. And yes this isn't probably something a lot of people are doing, even though maybe they should. Anyway, the fix is pretty simple:
The added code stops the error and stops the multiple addition of directives. It also warns that it happened, but this isn't important since everything runs fine anyway.
This would however require a new variable like added_directives = {}; being added to the collectDirectives function to gather the directive names as they are collected.
And I understand that this might not be a feature that will ever be added, but it took days to track down what was going on. The error message is correct, and even tells you it is the same directive. So I wanted to document it somehow so others who might come across this, won't have to go through the same grinding process trying to figure out what the heck is going on.