1

I am using Angular Meteor and I have a controller that subscribes to a publish-composite publish which returns two cursors. What I am trying to do is to ng-repeat on one cursor and get value from the second cursor based on the value of the first one. Like this:

{{getName(a.id)}}

where a is one object of the first cursor, and in the controller I have $scope.getName(id) function that returns name from the second cursor, like this:

name = second.find({ID: id}).fetch()[0].name

it worked but the problem is the getName function gets hit for unnecessary number of times. Is there a better way to get data from the second cursor based on ng-repeat object of the first cursor? Is nested ng-repeat the way to do? How can I do it?

Thanks.

2
  • What does "returns two cursors" mean? Commented May 17, 2016 at 15:27
  • Is there no way you can merge the two arrays if it's a 1-1 lookup after you get both "cursors" and ng-repeat over the flat data structure? In fact, if the indexes are the same, what about something like this? stackoverflow.com/questions/28094394/… Commented May 17, 2016 at 15:31

1 Answer 1

1

It seems as if you are focused on the performance of the ng-repeat. Glad you feel this way! From what I remember, the ng-repeat has been a focus of optimization across many 3rd party libraries and discussions.

In your case, my first attempt would be to bind the value inside the ng-repeat only once. You can do this using the :: syntax on the expression.

For example, this would call the expression once.

<ul ng-repeat="a in items">
  <li>{{::getName(a.id)}}</li>
</ul>

At the end of your question you mentioned a nested repeat but your question only mentions a single use of it. Am I missing something?

Disclaimer: I've never used Angular Meteor (or even standalone Meteor) so there could very well be a better way do solve your problem.

via: https://docs.angularjs.org/guide/expression

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.