How to use ng-repeat without an html element

后端 未结 8 1535
暖寄归人
暖寄归人 2020-11-30 23:35

I need to use ng-repeat (in AngularJS) to list all of the elements in an array.

The complication is that each element of the array will transform to ei

8条回答
  •  囚心锁ツ
    2020-12-01 00:20

    You might want to flatten the data within your controller:

    function MyCtrl ($scope) {
      $scope.myData = [[1,2,3], [4,5,6], [7,8,9]];
      $scope.flattened = function () {
        var flat = [];
        $scope.myData.forEach(function (item) {
          flat.concat(item);
        }
        return flat;
      }
    }
    

    And then in the HTML:

    {{item}}

提交回复
热议问题