1

I've got a filter like

angular.module(Bt.config.site.ng_app_name)
    .filter('range', function () {
        return function (input, min, max, padding){
            min = parseInt(min);
            max = parseInt(max);
            padding = padding ? padding : false;
            for (var i=min; i<=max; i++){
                input.push(padding ? ("00" + i).slice (-2) : i + '');
            }
            return input;
        };
    });

a select

<select ng-options="n for n in [] | range:1:31:true" name="day" value="{{contestant.day}}" ng-model="contestant.day">
    <option value="">DD</option>
</select>

the output is

<select ng-model="contestant.day" value="" name="day" ng-options="n for n in [] | range:1:31:true" class="ng-pristine ng-valid">
    <option value="" class="">DD</option>
    <option value="0">01</option>
    <option value="1">02</option>
    <option value="2">03</option>
    // and so on
</select>

it should be

<select ng-model="contestant.day" value="" name="day" ng-options="n for n in [] | range:1:31:true" class="ng-pristine ng-valid">
    <option value="" class="">DD</option>
    <option value="01">01</option>
    <option value="02">02</option>
    <option value="03">03</option>
    // and so on
</select>

Thanks in advance.

1 Answer 1

3

The angular generated options might not have the option values what you would have expected.

When the source is an array the values would be indexes and key names when the source is an object.

But that should not be a problem cos whenever the user switches options, angular looks up at the indexed position inside the source and assigns that value to the model:

So in your case if the user selects 01, contestant.day would still hold 01 and not just 1.

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.