Rachitta A Dua
Rachitta A Dua

Reputation: 358

AngularJS access another array with $index under ng-repeat

I new to AngularJS and wish to access two arrays under ng-repeat. This is my code:

<tr ng-repreat="find in findOptions">
<td>find.first</td>
<td>find.second</td>
<td>{{ search[{{$index}}].third }}</td>
</tr>

search is another array that I want to access here

Upvotes: 1

Views: 723

Answers (2)

Sumit Deshpande
Sumit Deshpande

Reputation: 2155

Created JSFiddle Demonstration - https://jsfiddle.net/qtksp1kj/

Hope this will help!

<body ng-app="SampleApp">
  <table ng-controller="fcController" border="1px">
    <thead>
      <tr>
        <td>Name</td>
        <td>Address</td>
        <td>LandMark</td>
      </tr>
    </thead>
    <tbody ng-repeat="element  in myArray">
      <tr>
        <td>{{element.name}}</td>
        <td>{{element.address}}</td>
        <td>{{myArray1[$index].landMark}}</td>
      </tr>
    </tbody>
  </table>
</body>


var sampleApp = angular.module("SampleApp", []);
sampleApp.controller('fcController', function($scope) {
  $scope.myArray = [{
    'name': 'Name1',
    'address': 'H-1 China Town'
  }, {
    'name': 'Name2',
    'address': 'H-2 China Town'
  }];

  $scope.myArray1 = [{
    'landMark': 'Near Dominos'
  }, {
    'landMark': 'Near Airport'
  }];
});

Upvotes: 1

Pankaj Parkar
Pankaj Parkar

Reputation: 136134

You can't have iterpolation inside a intepolation again, basically you could access scope variable directly inside it.

You could simply directly use $index to access array.

search[$index].third

Upvotes: 3

Related Questions