javascript - angularjs ng-repeat evaluated with ng-if -


i'm looking way ng-repeat expression. here have.

<tr ng-cloak id="{{$index}}"           ng-repeat-start="item in currentcontoller.items |            orderby: '-time'">     <td>item.a</td>     <td>item.b</td> </tr> 

what looking this, firstitemonly checkbox

<tr ng-cloak id="{{$index}}"           ng-repeat-start="item in currentcontoller.items |            orderby: '-time' |            if ({{firstitemonly}}) {limitto: 1}"> //this line needs added     <td>item.a</td>     <td>item.b</td> </tr> 

the key solving problem think outside of box. instead of trying use expression within ng-repeat, add expression collection itself:

// create function returns relevant collection of items $scope.getitems = function() {     // if first item only, return first item     if (this.firstitemonly)     {         return this.items.slice(0, 1);     }      // otherwise, return items     return this.items; };  ...  <tr ng-cloak id="{{$index}}"     ng-repeat-start="item in getitems() | orderby: '-time'"> 

Comments

Popular posts from this blog

facebook - android ACTION_SEND to share with specific application only -

python - Creating a new virtualenv gives a permissions error -

javascript - cocos2d-js draw circle not instantly -