Angular js with codeigniter

I want to show data in a table with angular js. I have tried many code but didn't solve my problem. Please help

Here is my code of View page..

Script code

<script>
    var app = angular.module('myApp', []);
    app.controller("customersCtrl", function($scope, $http) {   
    $http.get('<?php echo base_url('items/getRecords'); ?>').
success(function(data, status, headers, config) {       
    $scope.users = data;
});
 });
</script>

HTML Code

  <div ng-app="myApp" ng-controller="customersCtrl">                
            <table class="datatable table table-striped table-bordered" id="example">
                <thead>
                    <tr>                    
                        <th>Product Code</th>                       
                        <th>Product Name</th>                           
                    </tr>
                </thead>
                <tbody>

                    <tr class="gradeA" ng-repeat="x in users">

                        <td style="text-align:center;">{{x.item_code}}</td>                         
                        <td style="text-align:center;">{{x.item_name}}</td>         

                    </tr>

                </tbody>
            </table>

        </div>

On Controller

 public function getRecords(){

    $this->load->model('item_model');
    $data=$this->item_model->getTransactionData();
    $this->output->set_header('Content-type: application/json');
    $this->output->set_output(json_encode($data));
}

And finally on Model

public function getTransactionData(){


    $query=$this->db->get('ac_itrans');
    return $query->result();

}

Here is Json format of my result:

  [{"itrans_id":"17","cocode":"OFLT","yearcode":"OFLT16","vseries":"S","vnum":"1","vdate":"2015-10-06","linenum":"1","item_type":"services","item_code":"26","item_name":"AC Repair"}];

Console log

Answers


please read tutorial from here, there is good way to do integrate angularjs with codeigniter php framework.


Apparently, code is correct.

you need to debug to check whether you are getting right JSON format. check this using console.log($scope.user)..instead of data.length.

use devtool to see what it returns. Put that snapshot here.

and don't you need to initialize the user !

 $scope.user = [];

Need Your Help

Codeigniter Profiler not showing INSERT and UPDATE queries

php codeigniter

I am working on codeigniter 3.0 and need to print all queries in page.

IOS Jailbreak How do intercept SMS / Text Messages

ios sms hook jailbreak intercept

I'm currently trying to write an application that intercepts text messages and reacts depending on the content of that message.