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();
    }
}

 

posted @ 2016-01-30 00:27  zcynine  阅读(468)  评论(0编辑  收藏  举报