admin管理员组文章数量:1435859
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
<input type = "text" ng-model = "sort">
<ul class = "list-unstyled">
<li ng-repeat = "ment in dishCtrl.dishments | orderBy: sort">
<blockquote class = "blockquote">
<p>{{ment.rating}} Stars </p>
<p>{{mentment}}</p>
<footer>{{ment.author}}, {{ment.date | date}</footer>
</blockquote>
</li>
It doesnt work, I already searched but can't find this kind of example.
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
<input type = "text" ng-model = "sort">
<ul class = "list-unstyled">
<li ng-repeat = "ment in dishCtrl.dish.ments | orderBy: sort">
<blockquote class = "blockquote">
<p>{{ment.rating}} Stars </p>
<p>{{ment.ment}}</p>
<footer>{{ment.author}}, {{ment.date | date}</footer>
</blockquote>
</li>
It doesnt work, I already searched but can't find this kind of example.
Share Improve this question edited May 8, 2016 at 14:36 Juan Serrats 1,3585 gold badges24 silver badges31 bronze badges asked May 8, 2016 at 14:06 Antonio KidaAntonio Kida 538 bronze badges4 Answers
Reset to default 5You have to define the variable in the controller:
var sort = '';
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="ments in dishDetailCtrl.dish.ments | orderBy: dishDetailCtrl.sort">
There is a very tiny mistake in your code. There should be no space after orderBy
expression.
<li ng-repeat = "ment in dishCtrl.dish.ments | orderBy:sort">
If above doesn't work try, putting it in single quotes like 'sort'
You need bind an action on this input it can be simple ng-enter directive or a submit button.
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 = "ment in dishCtrl.dish.ments | orderBy: dishCtrl.sort">
本文标签: javascriptOrder by elements based on input textangularjsStack Overflow
版权声明:本文标题:javascript - Order by elements based on input text, AngularJS - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745669280a2669473.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论