2

I want to loop html select option with a number(5).

I have tried below code but not working :

<select>
  <option ng-repeat="n in [] | range:5" value="{{$index+1}}">{{$index+1}}</option>
</select>

1 Answer 1

3

Range limits the current array. But your array doesn't have anything. ng-repeat is working for defined array. So you can define an array in your scope and use it.

html

<div ng-app ng-controller="TestController">
  <select>
    <option ng-repeat="n in myNumberArray" value="{{$index+1}}">{{$index+1}}</option>
  </select>
</div>

controller

function TestController($scope) {
    $scope.myNumberArray = new Array(5);
}

EXAMPLE

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.