【问题标题】:Angular Datatable ng-click not workingAngular Datatable ng-click 不起作用
【发布时间】:2015-12-31 08:14:56
【问题描述】:

在 ng-click 角度数据表上遇到问题。我正在使用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')
    }

删除按钮不起作用。

代码有什么问题吗?

【问题讨论】:

  • 你需要 $compile 。
  • 嗨,我试过了。但不工作。 :|
  • @你谢谢。我错过了这个选项 .withOption('createdRow', function(row, data, dataIndex) { // 重新编译以便我们可以将 Angular 指令绑定到 DT $compile(angular.element(row).contents())($scope) ; })

标签: javascript angularjs datatable


【解决方案1】:
 $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')
    }

【讨论】:

  • 除了你的代码,你能解释一下你做了什么以及为什么它有效。
猜你喜欢
  • 2018-04-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-05-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多