0
<!--customers view-->

<div class="container">
    <div class="row">
        <div class="col-md-12">
            <table class="table table-responsive table-striped">
                <tr>
                    <th ng-click="doSort('name')">Name</th>
                    <th ng-click="doSort('city')">City</th>
                    <th ng-click="doSort('order')">OrderTotal</th>
                    <th ng-click="doSort('joined')">Join</th>
                    <th>Orders</th>
                    <th>Delete</th>
                </tr>
                <tr ng-repeat="cust in customers |filter:customerFilter | orderBy:sortBy:reverse" class="repeat-animation">
                    <td>{{ cust.name | uppercase }}</td>
                    <td>{{ cust.city }}</td>
                    <td>{{ cust.orderTotal | currency: 'AED ' }}</td>
                    <td>{{ cust.joined | date}}</td>
                    <td><a href="#/orders/{{cust.id}}">View Orders</a></td>
                    <td class="center"><span class="glyphicon glyphicon-remove delete" ng-click="remove(cust.id)"></span></td>
                </tr>
            </table>
        </div>
    </div>
</div>


/*------------Customer Controller-------------------*/
myApp.controller('CustomersController', ['$scope', 'customersFactory', 'appSettings', function($scope, customersFactory, appSettings) {

    var customers = [];
    $scope.sortBy = 'name';
    $scope.reverse = false;
    $scope.appSettings = appSettings;

    function init() {
        $scope.customers = customersFactory.getCustomers();
    }

    init();

    $scope.doSort = function(propName) {
        $scope.sortBy = propName;
        $scope.reverse = !$scope.reverse;
    }

    $scope.remove = function(customer) {
        customersFactory.remove(customer);
    };

}]);



/* factory remove method*/
factory.remove = function(item) {
    factory.customers = _.reject(factory.customers, function(element) {
        return element.id === item.id;
    });
};

return factory;

I am making table which display the customers and their order and I want to delete the particular orders with the help of underscore reject method, but it is not deleting. My angular version is 1.5. Can anyone suggest the solution?

Łukasz
  • 2,131
  • 1
  • 13
  • 28
  • 1
    Don't you need to update the customers after you removed one? `$scope.customers = customersFactory.remove(customer);` – Alon Eitan Jun 05 '16 at 13:04
  • Looks like you're changing the `factory.customers` reference when you remove an item and angular is still looking at the old reference. Change `factory.remove` to splice the item from the list (e.g. using `_.findIndex`) – Gruff Bunny Jun 06 '16 at 08:56
  • Check this link: [Delete in angularjs](http://stackoverflow.com/questions/14250642/angularjs-how-to-remove-an-item-from-scope) – S. Divya Jun 06 '16 at 09:36

0 Answers0