Save scope items on ng-sortable change order

239 Views Asked by At

I need to change the order of scope, save but me back an error that save() is not a function.

I'm using restangular to create the objects.

The function is triggered Onsort, I tried using http, but also gives me error.

$scope.onChange = function() {
        ApiRestangular.all($scope.section).getList($scope.query).then(function(res){
            $scope.items = res;

            order = ApiRestangular.copy(res);

            console.log(order);

            $scope.sortOptions = {
                animation   : 150,
                onSort: function(){
                    order.put().then(function(){
                        toast.msgToast($scope.section+ ' ...Ordem atualizada!');
                    });
                }
            };
        });
    };
1

There are 1 best solutions below

2
On

There are a few issues here but I think the biggest one is that "save()" really isn't a function. I believe the correct syntax is $save().

Here is the documentation.

https://docs.angularjs.org/api/ngResource/service/$resource

Without seeing the rest of your controller code it is tough to say what other problems there may be (dependency injection?). But this should get your started.