ng-click在Ajax Datatable + Codeigniter中不起作用

时间:2018-07-03 09:01:44

标签: php angularjs codeigniter datatable angular-routing

我有一个案例,带有选项编辑和删除数据的CRUD数据。但是我有约束ng-click =()无法在控制器ajax_list()调用中工作:

这是我的代码:

UserController(CI)

public function ajax_list(){
        $lists = $this->model_user->get_datatables();
        $data = array();
        $no = $_POST['start'];
        $nomor = 1;
        foreach($lists as $key => $item){
            $no++;
            $row = array();
            $row[] = $item->username;
            $row[] = '<a type="button" class="btn btn-xs btn-warning" href="#/editUser/'.$item->kode_user.'" title="Edit" ><i class="fa fa-pencil" ></i></a>
                    <button type="button" class="btn btn-xs btn-danger" ng-click="deleteUser()" title="Hapus"><i class="fa fa-trash"></i></button>';
            $data[] = $row;
        }
        $output = array(
            "draw" => $_POST['draw'],
            "recordsTotal" => $this->model_user->count_all(),
            "recordsFiltered" => $this->model_user->count_filtered(),
            "data" => $data
        );
        echo json_encode($output);
    }

script.js(angularjs)

var inticafeApp = angular.module('inticafeApp', ['ngRoute']);
inticafeApp.config(function ($routeProvider, $locationProvider) {
    $locationProvider.hashPrefix('');
    $routeProvider
    .when('/', {
        templateUrl: 'dashboard/index',
        controller: 'dashboardController'
    })

    .when('/user', {
        templateUrl: 'masterdata/user',
        controller: 'userListController'
    })

});

inticafeApp.controller('userListController', function ($scope) {
    $scope.deleteUser = function () {
        // $http.post(siteUrl + "masterdata/user/delete" + id).success(function (response) { alert('yes')})
        alert('a');
    }
})

在$ row []中,我从php渲染了html,但是ngclick无法正常工作。

你能帮我吗?

1 个答案:

答案 0 :(得分:0)

尽量避免将PHP用于HTML输出。如果您使用trustAsHtml或类似的名称添加,它将不会被angularjs编译。最好只是将$item->kode_user返回数组,然后使用ng-repeat将其打印在页面上。

相关问题