ng-repat无法在数组中工作

时间:2017-03-21 14:56:38

标签: angularjs arrays angularjs-ng-repeat

我尝试重复我的数据,但它不起作用

<div ng-if="isDocPresent(doc, $index)">
      <div ng-repeat="x in arr[$index] track by $index">
        <div class="title" ng-if="$last">{{x || 'N/A'}}</div>
        {{x.title}} {{x.document_url}} {{document_url}}
        </div>
      </div>

控制器

$scope.isDocPresent = function(doc, index) {
      if ($scope.parentCtrl.docsList && $scope.parentCtrl.docsList[appConstants.DOCUMENT_CATEGORY[doc]])
      {
        $scope.arr[index] = $scope.parentCtrl.docsList[appConstants.DOCUMENT_CATEGORY[doc]];
        return true;
      }
    };

它始终只打印 {{x || 'N/A'}}

1 个答案:

答案 0 :(得分:0)

您正在尝试访问$ index变量,该变量在ng-repeat中定义,即不在其周围的包含块中。试试这个:

<div ng-repeat="x in arr track by $index">
  <div ng-if="isDocPresent(doc, $index)">
    <div class="title" ng-if="$last">{{x || 'N/A'}}</div>
      {{x.title}} {{x.document_url}} {{document_url}}
    </div>
  </div>
</div>