0

Now I am trying to set a default value for a select dropdown. but couldn't get it down, code:

<div class='paymentmethods subcontent' ng-switch on="editpaymentmethod">{{editselection.selectedmethod=Memethods[paymethodindex]}}// This gives me what I need,but select doesn't. confused?
            <select ng-model='editselection.selectedmethod' ng-init="editselection.selectedmethod=Memethods[paymethodindex]" id='methods' ng-switch-when='Y'>
              <option ng-repeat="method in Memethods" value="{{method}}">{{method}}</option>            
            </select>
            <select ng-model='editselection.selectedmethod' ng-init="editselection.selectedmethod=companies[paymethodindex]" ng-switch-when='N' style='float:left'>
              <option ng-repeat='companyoption in companies' value="{{companyoption}}">{{companyoption}}</option>
            </select>
            </div>

JS:

$scope.paymethodindex = $scope.Memethods.indexOf(paymethod);
            console.log($scope.paymethodindex);
            if(reimbursement=='N')
                            {
            $scope.paymethodindex = $scope.companies.indexOf(paymethod);            
                            }

I use paymethodindex to set default value for select dropdown. I can even print out in the page with {{editselection.selectedmethod=Memethods[paymethodindex]}}, I think the index part works fine, any idea?

1 Answer 1

1

Use ng-selected to default the selected option, see example in the doc.

Alternatively, use ng-options instead of ng-repeat to generate your options.

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.