美文网首页
ajax动态生成页面angularjs事件无法加载,ngclic

ajax动态生成页面angularjs事件无法加载,ngclic

作者: 神力无敌_61b6 | 来源:发表于2017-07-20 17:27 被阅读0次

初接触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)
            });
        }
}

相关文章

网友评论

      本文标题:ajax动态生成页面angularjs事件无法加载,ngclic

      本文链接:https://www.haomeiwen.com/subject/tottxxtx.html