kszyrver
kszyrver

Reputation: 954

AngularJs : Referencing to the value of an object inside angular {{ }} html markup

I have an object like this:

items = [{a:1,b:2},{a:3,b:4}];
lists = [a,b];

Then this is my markup:

<div ng-repeat="item in items">
     <div ng-repeat="list in lists">
          // I want to display like this
          {{ item.{{list}} }}
     </div>
</div>

Upvotes: 0

Views: 49

Answers (3)

Arrays should be like,

$scope.items = [{a:1,b:2},{a:3,b:4}];
$scope.lists = ["a","b"];

Html should be like,

<div ng-repeat="item in items">
  <div ng-repeat="list in lists">
    {{item[list]}}
  </div>
</div>

Now this will work.

Upvotes: 0

Thermite
Thermite

Reputation: 1

the lists array should have quotes around the a and b...

lists = ['a','b'];

then the markup should be...

<div ng-repeat="item in items">
    <div ng-repeat="list in lists">
        {{item[list]}}
    </div>
</div>

Upvotes: 0

Rambler
Rambler

Reputation: 5482

Access it in the following manner :

<div ng-repeat="item in items">
 <div ng-repeat="list in lists">
      {{item[list]}}
 </div>
</div>

Upvotes: 1

Related Questions