angularjs - Angular switch in repeater -


given list such

var list = ['one','two','three']; 

in angular, want iterate through list rendering items. like:

<ul ng-controller="main">     <li ng-repeat="item in list" ng-switch on="item">         <span ng-switch-when="one">{{item}}</span>     </li> </ul> 

and have output this:

<ul>     <li><span>one</span></li> </ul> 

instead, get:

<ul>     <li><span>one</span></li>     <li></li>     <li></li> </ul> 

i have tried ng-hide woefully inefficient since have large number of items , want display 1 or 2 , ng-hide renders of them , hides inactive ones css. problem because doing in jquery mobile app tries decorate list items, including hidden ones, killing performance.

jsfiddle @ http://jsfiddle.net/ghendricks/mxu3a/

you correct ng-hide should not used here, job filters. can provide custom function filter list: http://jsfiddle.net/ermvj/

$scope.selectone = function (input) { return input == "two" || input == "one"; }; 
    <li ng-repeat="l in list | filter:selectone">         <span>{{l}}</span>     </li> 

Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

javascript - addthis share facebook and google+ url -

ios - Show keyboard with UITextField in the input accessory view -