How to add DOM Elements (Angular directives) via jQuery's .append()?

前端 未结 6 1828
半阙折子戏
半阙折子戏 2020-12-13 23:40

Is there any way to add an element that is an Angular directive with jQuery methods like append() and have Angular do its compilation/linking to make it work as

6条回答
  •  不知归路
    2020-12-14 00:16

    The right way to go is to use: $compile and in case your directive returns: directive definition object (which is btw. the recommended way to go) you can then call link function on it (to inject scope, for example).

    $('body').append($compile("")(scope));
    scope.$apply(); 
    

提交回复
热议问题