在angularJS中删除记录时显示[$ rootScope:inprog] $ digest已在进行中

时间:2016-01-08 08:27:39

标签: angularjs

删除记录时,它会在控制台中显示错误。但是当我点击第二次删除记录但没有显示更新的列表时。  我从URL传递参数(ID)并传递这些ID' ID'到控制器。我正在尝试删除记录后刷新列表。

app.controller('user',function($scope,$routeParams,$http,$location){
    /* This is function for deleting the particular record */
    $scope.deleteuser = function(){
        $scope.emp_id = $routeParams.emp_Id; // Id which is passing from URL
                var request = $http({
                method: "post",
                url: "delete-user.php",
                data: {
                    emp_id: $scope.emp_id,
                },
                headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
            });

            /* Successful HTTP post request or not */
            request.success(function (data) {
                if(data == 1){
                    $location.path('/user_listing');
                    alert("Employee record Deleted successfully"); 
                }
                else {
                    alert("Error While deleting Record");
                }
            });
    };

    }).
    config(['$routeProvider',function($routeProvider){

    $routeProvider
    .when('/user_listing',{

            templateUrl:'user-listing.html',
            controller:'user'
    })
    .when('/user-delete/:emp_Id',{ // passing the Id to above deleteuser function

            templateUrl:'user-listing.html',
            controller:'user'
    });

        }]);
-------------------------------------------------------------------
  

MY HTML PAGE

   <!-- /.panel-heading -->
<div class="panel-body">
    <div class="dataTable_wrapper">
        <table class="table table-striped table-bordered table-hover" id="dataTables-example">
            <thead>
                <tr>
                    <th ng-click="sort('first_name')">First Name</th>
                    <th >Last Name</th>
                    <th>Email</th>
                    <th>Gender</th>
                    <th ng-click="sort('city')">City</th>
                    <th>Action</th>
                </tr>
            </thead>
            <tbody >
                <tr class="odd gradeX" dir-paginate="user in users | filter:search|orderBy:sortKey:reverse|itemsPerPage:paginate">
                    <td>{{user.first_name}}</td>
                    <td>{{user.last_name}}</td>
                    <td>{{user.email}}</td>
                    <td>{{ user.gender}}</td>
                    <td>{{user.city}}</td>
         <!-- Passing the parameter to controller -->   
                    <td><a href="#/user-delete/{{user.emp_id}}" ng-click="deleteuser();"><i class="fa fa-trash fa-fw"></i></a></td>
                </tr>
            </tbody>
        </table>

        <dir-pagination-controls max-size="5" direction-links="true" boundary-links="true" > </dir-pagination-controls> 
    </div>

</div>
<!-- /.panel-body -->

0 个答案:

没有答案