Order By Elements Based On Input Text, AngularJS
I'm trying to order a list of items in anguarjs based on an input text, so if i write in my input 'author' the list will be ordered by author my code is this ;
Then you have to define the ng-model directive to bind the input value to this variable:
<input type="text" ng-model="dishDetailCtrl.sort">
And then you can apply the filter:
<div class="well" ng-repeat="comments in dishDetailCtrl.dish.comments | orderBy: dishDetailCtrl.sort">
Solution 2:
There is a very tiny mistake in your code. There should be no space after orderBy
expression.
<li ng-repeat = "comment in dishCtrl.dish.comments | orderBy:sort">
If above doesn't work try, putting it in single quotes like 'sort'
Solution 3:
You need bind an action on this input it can be simple ng-enter directive or a submit button.
Solution 4:
Because you are using controller as syntax, as i can see from your ng-repeat, change
<input type = "text" ng-model = "sort">
to
<input type = "text" ng-model = "dishCtrl.sort">
And also update your ng-repeat:
<li ng-repeat = "comment in dishCtrl.dish.comments | orderBy: dishCtrl.sort">
Post a Comment for "Order By Elements Based On Input Text, AngularJS"