Add directive from inside another directive in angularjs

后端 未结 1 1151
长发绾君心
长发绾君心 2020-12-30 15:21

Adding directive from inside another directive, makes the browser to hang.

What im trying to do is

1) Alter an custom element directive (like

1条回答
  •  礼貌的吻别
    2020-12-30 16:02

    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.

    0 讨论(0)
提交回复
热议问题