Negating expression of ng-repeat filters

03 Nov 2013 » {[{categoryPostCurrent}]}

Official tutorial of angularJS present you how to make a simple filter tied to an ng-repeat element according to the value of ng-model of an input element. Here is an example:

    <input ng-model="filterpost"/>
    <ul>
        <li ng-repeat="post in posts | filter:filterpost" >{{ post.title }}</li>
    </ul>    

The official API of the filter $filtermention that it's possible to negate the expression but if you try <li ng-repeat="post in posts | filter:!filterpost" > you will notice that it does not seem to work. This is just because you have ommited the quote. So the right code is :

    <input ng-model="filterpost"/>
    <ul>
        <li ng-repeat="post in posts | filter:'!'+filterpost" >{{ post.title }}</li>
    </ul>    

Voir aussi...

comments powered by Disqus