angularJS DOM element() $compile()

我们可以使用angularJS来动态地添加和删除节点

与jQuery不同的是,html字符串需要经过$compile()方法的编译才能产生html的DOM的node

注意element()方法的使用

//通过$compile动态编译html
var html="<div ng-click='test()'>}</div>";
var template = angular.element(html);
var mobileDialogElement = $compile(template)($scope);
angular.element(document.body).append(mobileDialogElement);
 
// remove移除创建的元素
var closeMobileDialog = function () {
    if (mobileDialogElement) {
        mobileDialogElement.remove();
    }
}
原文地址:https://www.cnblogs.com/zcynine/p/5170359.html