Bind an externally loaded DOM element to Angular's scope

不想你离开。 提交于 2019-12-06 16:37:44

For AngularJS to "notice" the directive, it'd need to compile the element, which is not done automatically except when bootstrapping the application. So either the API needs to allow you to pass DOM Element to it (and you need to $compile and link it before you pass it on), or you need to find the element after it is added to DOM and then $compile and link it. AFAIK, if you cannot do either of those, then what you're asking is impossible.


If you manage to get hold of the element, compiling it is as simple as calling

$compile(element)($scope);

where $scope is the scope you want to link it to (possibly even $rootScope).

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!