Adding directive from inside another directive, makes the browser to hang.
What im trying to do is
1) Alter an custom element directive (like
Calling $compile
on the element of the directive itself will cause the same directive to run again, which then repeats that process - forever. In the angular source code of many directives, you can see that they handle this situation like this: $compile(element.contents())(scope);
using element.contents()
rather than just element()
. That means that everything inside of the element is compiled and the directives/data-bindings are registered and no loop is created.
If you do need to $compile
the element itself, either replace the original element entirely or remove the original directive from it (remove the attribute, change node type, etc) before compiling.