TMH
TMH

Reputation: 6246

While lower than value

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?

Upvotes: 1

Views: 76

Answers (1)

chridam
chridam

Reputation: 103435

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

Upvotes: 5

Related Questions