jqueryregexangularjsangularjs-ng-repeatjquery-attributes

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.


Solution

  • 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>