10
8

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

AngularJSでng-repeatを入れ子にした時の親のindexを取得する

Last updated at Posted at 2014-08-15

ng-repeatを入れ子にした時に親のIndexを取得したかったので

<div ng-repeat="hoge in hoges">
  <div ng-repeat="fuga in fugas">
    <p ng-show="$parent.$index % 3 == 0">hoge[3n].fugas</p>
    <p ng-show="$parent.$index % 3 != 0">hoge[!3n].fugas</p>
  </div>
</div>

何をしたいかわからないコードだけど、とりあえず$parent.$indexで親のng-repeatからIndexを持ってこれるらしい。

<div ng-repeat="(hogeIndex, hoge) in hoges">
  <div ng-repeat="fuga in fugas">
    <p ng-show="hogeIndex % 3 == 0">hoge[3n].fugas</p>
    <p ng-show="hogeIndex % 3 != 0">hoge[!3n].fugas</p>
  </div>
</div>

こんな感じでも書けるらしい

10
8
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
10
8

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?