Angularjs ng-repeat nesting How to get the outer layer $index_angularjs

Source: Internet
Author: User

An example of a real project is to traverse the rows and columns of the table, each row needs to display the current first few lines, I immediately thought of using $index, just like chopping melon cut vegetables, everything so flowing, it is too easy, so the following code.

<!--repeat data row-->
<tr ng-repeat= "row in rows track by Row.id" >
  <td ng-repeat= "Col in Row.col Umns track by Col.id ">
    <span ng-if=" col.id = 0 "ng-bind=" $index "></span>
  </td>
< /tr>

But when my program ran, I found that I was getting the $index feel strange, I think it must be the way I open the wrong, I am crazy to press a few F5, but the fact is that my program out of the bug, because it is the index of the column loop. I'm so crazy about this. Are you messing with me?

After thinking, I thought of the nginit, so I have the following code,
What I'm trying to do is assign the $index to the Outerindex and output the Outerindex in the loop body.

<tr ng-repeat= "row in rows track by Row.id" ng-init= "Outerindex = $index" >
  <td ng-repeat= "Col in Row.columns Track by Col.id ">
    <span ng-if=" col.id = 0 "ng-bind=" outerindex "></span>
  </td>
</tr>

At this time the success achieved the desired results. Although this small problem is very simple, but for angular novice is still very egg ache, feel the answer is ready, but also say,
A little record, my road to Angularjs has just begun.

The above is the Angularjs ng-repeat nesting how to obtain the outer $index data collation, follow-up continue to supplement the relevant information, thank you for your support of this site!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.