简体   繁体   中英

AngularJS ng-repeat: Change Array

I want to change categoryAlpha into a different value (say, into categoryBeta ) in the following HTML + AngularJS:

 <div ng-repeat="x in categoryAlpha | limitTo:quantity"> <previews></previews> <hr /> </div> 

Since ng-repeat isn't a normal attribute, I don't think I can change it through jQuery attr() . Is my only solution regex, or is there an Angular/jQuery method that can change the value categoryAlpha ?

Thanks in advance.

You can for example create function which will return a collection for ng-repeat and assign it to scope. Something like:

// in your controller
$scope.getCategory = function getCategory() {
  return someCondition ? categoryAlpha : categoryBeta;
};

and then in your markup:

<div ng-repeat="x in getCategory() | limitTo:quantity">
  <previews></previews>
  <hr />
</div>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM