1

Say I have a variable x with a value of 7, I need to echo out this html

<a href="#" data-page="{{y}}">{{y}}</a>

Where y is 1,2,3... until y == x. How do I do this in Angular?

TMH
  • 6,096
  • 7
  • 51
  • 88

1 Answers1

5

Using this answer you can create a filter which does this for you:

HTML

<div ng-app='myApp' ng-controller="Main">
    <a href="#" ng-repeat="y in range(1,7)" data-page="{{y}}">{{y}}</a>
</div>

Controller

var myApp = angular.module('myApp', []);
function Main($scope){
  $scope.range = function(min, max){
    var input = [];
    for (var i=min; i<=max; i++) input.push(i);
    return input;
  };
};

JSFiddle

Community
  • 1
  • 1
chridam
  • 100,957
  • 23
  • 236
  • 235