Angular Datatable ng-click无效

时间:2015-10-03 03:42:09

标签: javascript angularjs datatable

在角度数据表上点击ng有问题。我正在使用https://l-lin.github.io/angular-datatables

这是我的代码

    $scope.dtOptions = DTOptionsBuilder.fromFnPromise(function(){
        return $resource(APIROOT + 'categories').query().$promise;
    })
        .withOption('order', [0, "asc"]);

    $scope.dtColumns = [
        DTColumnBuilder.newColumn('id', 'ID').withOption('searchable', false),
        DTColumnBuilder.newColumn('name', 'Name'),
        DTColumnBuilder.newColumn('', 'Actions').renderWith(function (data, type, full, meta) {
            return '<a class="btn btn-default btn-xs" href="#/edit/' + full.id + '"><i class="fa fa-pencil"></i></a> ' +
                '<button class="btn btn-danger btn-xs" ng-click="deleteItem(' + full.id + ')"><i class="fa fa-trash"></i></button>';

        })

    ];

    $scope.deleteItem = function (id) {
        alert('delete')
    }

删除按钮不起作用。

代码有什么问题吗?

1 个答案:

答案 0 :(得分:2)

 $scope.dtOptions = DTOptionsBuilder.fromFnPromise(function(){
        return $resource(APIROOT + 'categories').query().$promise;
    })
.withOption('createdRow', createdRow)
        .withOption('order', [0, "asc"]);
function createdRow(row, data, dataIndex) {
        // Recompiling so we can bind Angular directive to the DT
        $compile(angular.element(row).contents())($scope);
console.log("test");
    }
//now ur deleteItem function is complied and it'll work.
 $scope.deleteItem = function (id) {
        alert('delete')
    }