初接触angularjs,遇到很多问题,今天在项目中遇到动态html无法触发ngclick绑定的事件
主角就是$compile动态编译服务
动态生成html后,包含的ng标签使用$compile重新编译就能够正常使用
代码如下
app1.controller('task', function ($scope, $http,$compile) {
$scope.update= function (stats, id) {
data = {"status": stats, "id": id};
$http.post("/api", data)
.success(function (result) {
var $html = $compile(result)($scope);
$("#tasklist").html($html)
}).error(function (err) {
console.log(err)
});
}
}
网友评论