0

I have a case, CRUD data with option edit and delete data. But i have constraints ng-click=() cant work in controller ajax_list() call:

this is my code:

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');
    }
})

in $row[] i render html from php but ngclick not work.

can you help me?

muzamil indra
  • 147
  • 3
  • 14
  • https://stackoverflow.com/questions/14242455/using-jquery-datatable-with-angularjs – Atural Jul 03 '18 at 10:09
  • @sintakonte, i think that article less suitable, because my datatable is server side – muzamil indra Jul 05 '18 at 07:03
  • thats the problem - i'm pretty sure your angular controller initialises before you even get your data - and therefore its impossible for angular to trigger this click event - you need a directive or something like that - probably its better to use some library - take a look here http://l-lin.github.io/angular-datatables/archives/#!/welcome – Atural Jul 05 '18 at 08:22

1 Answers1

0

Try to avoid using PHP for the HTML-output. It will not be compiled by angularjs if u add it with trustAsHtml or something like that. Better just return the $item->kode_user in an array and then use ng-repeat to print it out on the page.

Mischa
  • 1,591
  • 9
  • 14