Get angularjs post value in controller

时间:2017-10-12 10:02:22

标签: angularjs codeigniter

I want to get post value which i have send in $http.post() in controller when i click on edit button.

view page

<table id="example1" class="table table-bordered table-striped">
<thead>
    <tr>
        <th>Sl No.</th>                                   
        <th>Name</th>                                    
        <th>Action</th>
    </tr>
</thead>
<tbody>                                    
    <tr ng-repeat="data in datas">
        <td>{{$index + 1}}</td>                                        
        <td>{{data.name}}</td>                                        
        <td>                                            
            <a class="btn btn-info btn-sm btn-fill" ng-click="editsource(data.id)" data-toggle="modal" data-target="#myModal"><i class="fa fa-pencil-square-o"></i>&nbsp;Edit</a>       

            <a class="btn btn-danger btn-sm btn-edit btn-fill delete"><i class="fa fa-trash"></i>&nbsp;Delete</a>
        </td>
    </tr>                               
</tbody>

My script

<script type="text/javascript">
var app = angular.module('myapp', []);
app.controller('tabletest', function ($scope, $http) {
    $http.get("<?php echo base_url() ?>admin/source_list_for_test")
            .then(function (response) {
                $scope.datas = response.data;
            });
    $scope.editsource = function (id) {//alert('hello');
        $http.post("<?php echo base_url() ?>admin/edit_source_for_test?id="+id).success(function (data) {
            alert(data);
            $scope.id = data['id'];
            $scope.name = data['name'];
        });
    };
});

controller

public function edit_source_for_test(){
    $id= $_GET['id'];
    $data['source_data'] = $this->admin_model->get_edit_source_for_test($id);
    echo json_encode($data['source_data']);
}

Above is my code but id not get in controller,How i get selected record id in controller.

0 个答案:

没有答案