0
`http://jsfiddle.net/SSSUUUSSS/Bsusr/1/`

The example is taken from here

I want to send reorderd list to a function to save new order of list items.

Community
  • 1
  • 1

1 Answers1

0

It really is not clear what you are asking here... my guess is that you are new to Angular and perhaps do not understand how $scope works with two way binding yet. If thats the case...

In short, two-way binding will cause your changes to $scope variables to propagate to the DOM without explicitly passing them to a function.

So there's no need to pass $scope.list into a function, just set $scope.list ( assuming $scope.list and your function are within the same scope of the containing controller function )

For example:

var reorderList = function (){
  $scope.list = $scope.list.sort();
  saveList ( $scope.list ); 
};

var saveList = function ( list ){
  $http.post ('api.php', list )
    .then ( function (response){});
};
Kit
  • 3,388
  • 1
  • 27
  • 24
  • I edited the question. I want to send reorderd list to a (save) function to save new order of list items. I want to fire save function when reordering is complated. –  Oct 02 '16 at 20:16
  • Ok... no offense, but you're asking basic stuff. So basic you've nearly answered the question yourself. 1) do reordering function 2) do save function. As I said in my post, you don't need to pass the $scope.list in as a parameter as it's accessible because it's in the same "scope". – Kit Oct 03 '16 at 13:17
  • For triggering the reorderList () function, take a look at $watch documentation or use something like onclick="reorderList ()" as an attribute of an appropriate DOM element. – Kit Oct 03 '16 at 13:32