AngularJs:引用angular {{}} html标记内的对象的值

时间:2016-06-02 03:56:48

标签: angularjs ng-repeat

我有一个这样的对象:

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

然后这是我的标记:

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

3 个答案:

答案 0 :(得分:1)

以下列方式访问它:

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

答案 1 :(得分:0)

lists数组应该在a和b ...

周围有引号
lists = ['a','b'];

那么标记应该是......

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

答案 2 :(得分:0)

阵列应该像,

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

Html应该是,

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

现在这将有效。