1

I have something like this:

[
  {name: 'Julian', number: 1},
  {name: 'Mike', number: 2},
  {name: 'Carlos', number: 3},
  {name: 'Juan', number: 4},
  {name: 'Kate',number: 5},
]

and an orderBy: 'number' in a ng-repeat. It is working perfect but I need to exchange that values of numbers, for example now I need that Juan has a number 2 and Mike has a number 4, and then I need them to reorder. I have a filter before that and the filter is receiving the correct change but then when it orderBy the number I don't know why it is ordering as the first time it oredered. It isn't taking in account that the number value had changed.

Anyone knows about a solution ?

Edited:

Here is an example of a kind of what I want to do:

http://jsfiddle.net/eWZHh/9/

1 Answer 1

4

I created a demo and it looks it works fine. You can see the data is changed in 2 seconds and the data and order filter will be updated automatically.

Edit: You need to put the ng-click button inside the controler's scope

<ul ng-app="myapp" ng-controller="MainCtrl">
    <button ng-click="changeOrder()">Change order</button>
    <li ng-repeat="user in users | orderBy: 'number'">{{ user.name }}, {{ user.number }}</li>
</ul>

Demo

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks for your answer, it seems to work for you but take a look at my example please :) You reentered all the data, I only changed the values.
The button is outside the controler's scope, you need to put it inside
Oh you were right, sorry. It is working, but I don't know why in my application it doesn't work :/ I used drag and drop and more things, i will have to take a look for other things, thanks :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.