Angular函数不是由datatable呈现的html触发的?

时间:2015-01-16 16:47:55

标签: jquery angularjs datatables

{
                        sTitle: "ANSWER_CORRECT",
                        mData:"ANSWER_CORRECT",
                        sClass: "readonly",
                        mRender: function(data, type, obj) {                             
                            return_string="<button type='button' ng-click='updateCA()'>Confirm</button>";
                            return return_string;
                        }

 },

myc.controller('AdminController',['$scope','$route',function($scope,$route){
      $scope.updateCA=function(){
               console.log("pop");
       }   

            $(document).ready(function() { 
                ini_table(); //everything above is in this function.

            });
    }

我正在使用数据表来渲染可能会触发函数updateCA的按钮。不幸的是,单击按钮时没有任何反应。没有错误或警告信息。我认为这可能是由于使用JQuery和Angular之间的不同范围造成的。所以,我尝试使用$scope.$apply(function(){ init_table() });没有运气。

1 个答案:

答案 0 :(得分:1)

试试这个

return_string="<button type='button' onClick='updateCA(); return false;'>Confirm</button>";

外部功能

function updateCA() {
    var scope = undefined;
    //Controller in body element 
    //<body ng-controller="yourController" id="body"> id is important
    scope = angular.element(document.getElementById("body")).scope();
    scope.$apply(function () {
        scope.updateCA();
    });
}

角度控制器

$scope.updateCA = function() {
        //logic here
    };