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?

3
  • stackoverflow.com/questions/14242455/… Commented Jul 3, 2018 at 10:09
  • @sintakonte, i think that article less suitable, because my datatable is server side Commented Jul 5, 2018 at 7: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 l-lin.github.io/angular-datatables/archives/#!/welcome Commented Jul 5, 2018 at 8:22

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.