2

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.

chakeda
  • 1,551
  • 1
  • 18
  • 40
  • please provide more information – Ed Knowles May 29 '15 at 16:35
  • I want to change `categoryAlpha` into `categoryBeta` using JavaScript. Is there another way to do this other than regex? – chakeda May 29 '15 at 16:36
  • I suspect there's a better way to get the ultimate result you seem to be going after. Why not change the contents of `categoryAlpha` rather than change which array is referenced? – Danny May 29 '15 at 16:36
  • What EdwardKnowles said. Do the two different "categories" have different data to display? – erp May 29 '15 at 16:37
  • @erp yes, they have different data. – chakeda May 29 '15 at 16:37
  • Under what circumstances does it need to change? Like does it need to reference a different array based on a certain value, and the other array if not? – erp May 29 '15 at 16:39
  • @danny The content of `categoryAlpha` and `categoryBeta` are currently hard-coded with mockup content, so that option is unavailable. @erp The circumstance is dependent on the current querystring. – chakeda May 29 '15 at 16:42
  • 1
    Right, but I think bgoscinski's answer below reflects the sort of thing I was thinking. You're attacking an Angular problem with a jQuery solution, when there's a very Angular way to do it. – Danny May 29 '15 at 16:44

1 Answers1

3

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>
Bartosz Gościński
  • 1,468
  • 1
  • 16
  • 28