AngularJS ng-options create range

后端 未结 8 883
鱼传尺愫
鱼传尺愫 2020-11-28 09:58

I am trying to create a select element that has a list of numbers 1 to pages where pages is a variable that is the number of pages I have. What i don\'t know how to do is to

8条回答
  •  囚心锁ツ
    2020-11-28 10:10

    Your way works fine. Another option that came to my head is to use a filter, so you don't have to pollute your controller with Range.

    JS:

    var myApp = angular.module('myApp', []);
    myApp.filter('range', function() {
      return function(input, min, max) {
        min = parseInt(min); //Make string input int
        max = parseInt(max);
        for (var i=min; i

    HTML:

    
    

    Example: http://jsfiddle.net/N3ZVp/1/

    P.S. in your example in your main post, you didn't put var in front of i. So i is declared as a global variable in your example.

提交回复
热议问题