question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to access nested ng-repeat elements

See original GitHub issue

I am trying something like:

element.all(by.repeater('suggestion_type in searchBoxData.suggestion_types')).then(function(rows) {
  for(var i=0;i<rows.length;i++){
    rows[i].then(function(){
      element.all(by.repeater('content in suggestion_type.contents')).then(function(rows_2) {
        console.log(rows_2);
      });
    });
  }
});

but I am getting duplicate rows…

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
hankduancommented, Jun 23, 2014

Sorry for the delay, missed this issue:

suppose your set up is as follows:

<div ng-repeat="x in list1"><div ng-repeat="y in list2">{{x}}{{y}}</div></div>

The reason you’re getting duplicates is because you’re iterating all of the nested elements many times (in fact you are iterating (list1.length)^2 * (list2.length) times instead of list1.length*list2.length as you intended), because in your inner loop, you’re not saying search within the outer ng-repeat, you’re searching within the entire dom.

This will fix it:

element.all(by.repeater('suggestion_type in searchBoxData.suggestion_types')).then(function(rows) {
  for(var i=0;i<rows.length;i++){
    rows[i].all(by.repeater('content in suggestion_type.contents')).then(function(rows_2) {
      console.log(rows_2);
      for(var j=0;j<rows_2.length;j++){
        rows_2.getText().then(function(text) {
          console.log(text);
        });
      }
    });
  }
});

note the rows[i].all(by.repeater...) instead of element.all(by.repeater...) in your inner loop.

To make it simpler you can just do this:

element.all(by.repeater('content in suggestion_type.contents')).each(function(elem) {
  elem.getText().then(function(text) {
    console.log(text);
  });
});

Hope this answers your question

0reactions
reddynrcommented, Dec 6, 2016

Hi All,

I am testing an example using protractor. I need to select the data which is showing in ng-repeate

  • getting error. Any help much appreciated. Thanks

    element.all(by.repeater(‘branch in branches’)).get(1).element(by.linkText(‘branchName’)).click()

    Read more comments on GitHub >

    github_iconTop Results From Across the Web

    json - Nested ng-repeat - Stack Overflow
    Day can have any number of Jobs, Jobs can be nested and contain any number of other Jobs. Now using this code <p...
    Read more >
    How To Use Nested ng-repeat In AngularJS - C# Corner
    The ng-repeat directive instantiates a template once per item from a collection like array, list etc. In this blog, I am using nested...
    Read more >
    Using ng-repeat in Nested Loops in AngularJS - ASPSnippets
    The TBODY element of the nested HTML Table has been assigned ng-repeat directive in order to iterate through all the items of the...
    Read more >
    ngRepeat - AngularJS: API
    The ngRepeat directive instantiates a template once per item from a collection. Each template instance gets its own scope, where the given loop...
    Read more >
    Nested objects/arrays with ng-repeat on Service Portal
    It should start with just element. First ng-repeat: ng-repeat = "element in c.data.element".
    Read more >

    github_iconTop Related Medium Post

    No results found

    github_iconTop Related StackOverflow Question

    No results found

    github_iconTroubleshoot Live Code

    Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
    Start Free

    github_iconTop Related Reddit Thread

    No results found

    github_iconTop Related Hackernoon Post

    No results found

    github_iconTop Related Tweet

    No results found

    github_iconTop Related Dev.to Post

    No results found

    github_iconTop Related Hashnode Post

    No results found