-1

I don't want to use any Javascript code or $scope variable. Just want to print 1,2,3,4,5 values in Drop Down using ng-options.

This is what I have tried:

<select ng-name="priority" ng-options="priority for priority in Range(1, 5)"></select>
Teemu
  • 22,918
  • 7
  • 53
  • 106
  • Did you try anything at all? If so, please show your code. – Sam Dec 30 '15 at 13:11
  • 2
    Then why to tag the question with JS, if you don't want to use it? – Teemu Dec 30 '15 at 13:12
  • 1
    There's plenty of good answers in the following thread: http://stackoverflow.com/questions/16824853/way-to-ng-repeat-defined-number-of-times-instead-of-repeating-over-array – Ethnar Dec 30 '15 at 13:13
  • I can't see ng-options used here http://stackoverflow.com/questions/16824853/way-to-ng-repeat-defined-number-of-times-instead-of-repeating-over-array – user3510767 Dec 30 '15 at 13:24
  • @user3510767 Please edit your question to add information (I've added your code from the comment above), and also explain what went wrong and how. I don't dare to add "But it's not working" to your question ; ). Something like "But the select element is not populated" would do? – Teemu Dec 30 '15 at 13:24
  • There is simple drop down box. In which, I want to print numbers from 1 to 5. I want to use ng-options directive and don't want to use any js code. How could I do that.? – user3510767 Dec 30 '15 at 13:35
  • Yes, that's already clear. What your current code does instead of expected results? Add the answer to your post, don't post is as a comment. – Teemu Dec 30 '15 at 13:40

1 Answers1

0

Working solution, within your requirements:

<select ng-model="priority" ng-options="priority for priority in [1,2,3,4,5]"></select>

Just in case, here's the plnkr to experiment with. If you have a quick look at the angular source code, you will see that ng-options requires select element as well as ng-model. Not sure what is the Range implementation mentioned in your example, but here is a very creative thread on this topic. Though, if your array is always the same and you really don't want to use scope (but why?), you're better off with the solution above.

Community
  • 1
  • 1
boyomarinov
  • 615
  • 4
  • 12