标签:
<div ng-controller="c10_1" class="frame" id="control">
<button ng-click="add()">添加元素</button>
<button ng-click="del()">删除元素</button>
</div>
<script type="text/javascript">
angular.module(‘a10_1‘, [])
.controller(‘c10_1‘, function ($scope, $compile) {
$scope.hello = ‘Hello,Angular!‘;
$scope.log = function() {
console.log(‘这是动态添加的方法!‘);
}//添加元素及其对象方法加变量
var html = "<div ng-click=‘log()‘>{{hello}}</div>";
var template = angular.element(html);
var newHtml = $compile(template)($scope);
$scope.add = function () {
angular.element(document.getElementById("control")).append(newHtml);
}
$scope.del = function () {
if (newHtml) {
newHtml.remove();
}
}
});
</script>
待续
标签:
原文地址:http://www.cnblogs.com/dengzy/p/5358071.html