2

AngularJS do not sort in ng-repeat. I did,

<div ng-repeat="list in lists">
<div style="float: left; margin-left: 5px;">
  <div id="tasks" >
    <h3>{{ list.name }}</h3>
    <ul>
      <li ng-repeat="card in cards | orderBy:'card.position'" ng-if="list._id == card.list">{{ card.position }}<button ng-click="take(card.position)">HERE</button>{{ $index }}</li>
      </ul>
      <form ng-submit="addTask(list._id, $index, newTask)">
        <input type="text" ng-model="newTask" placeholder="add a new task" required />
        </form>
  </div>
  </div>
</div>


console.log($scope.cards[0]);

And output of the above code is :

Object { _id: "59bc0936c84be51d70f786e7", name: "first", list: "59bbdeae1ebcd215a4b7af62", position: 7200, __v: 0, created: "2017-09-15T17:09:10.813Z", updated: "2017-09-15T17:09:10.813Z" }

https://i.sstatic.net/RF3k4.jpg

Where could I have made a mistake?

1 Answer 1

5

It should be just orderBy:'position'

<li ng-repeat="card in cards | orderBy:'position'" ng-if="list._id == card.list">{{ card.position }}<button ng-click="take(card.position)">HERE</button>{{ $index }}</li>

EDIT

if you want to ordery by multiple fields, put them inside an array like this,

<li ng-repeat="card in cards | orderBy:['position','list']" ng-if="list._id == card.list">{{ card.position }}<button ng-click="take(card.position)">HERE</button>{{ $index }}</li>
Sign up to request clarification or add additional context in comments.

Comments

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.