Nasuh
Nasuh

Reputation: 355

md-virtual-repeat by given number

I have some number that coming from database and I want to repeat some list over this number. Lets say 366 comes from database it has to repeat 366 times.

Below code is working but angular material's md-virtual-repeat does not support track by attribute. Is what I want achiveable?

$scope.number = 5; //Coming from database

$scope.getNumber = function(num) {
return new Array(num);   
}

<li ng-repeat="i in getNumber(number) track by $index">{{$index+1}}</li>

Upvotes: 0

Views: 1259

Answers (1)

camden_kid
camden_kid

Reputation: 12813

Do you mean something like this? - CodePen

This is taken from the Vertical Usage example from the demo page.

Markup

<div ng-controller="AppCtrl as ctrl" ng-cloak="" class="virtualRepeatdemoVerticalUsage" ng-app="MyApp">
  <md-content layout="column">
    <md-virtual-repeat-container id="vertical-container">
      <li md-virtual-repeat="item in ctrl.items" class="repeated-item" flex="">
        {{$index + 1}}
      </li>
    </md-virtual-repeat-container>
  </md-content>
</div>

JS

(function () {
  'use strict';

    angular
      .module('MyApp',['ngMaterial', 'ngMessages', 'material.svgAssetsCache'])
      .controller('AppCtrl', function() {
        this.items = new Array(366);        
      });
})();

Upvotes: 2

Related Questions