AngularJS How do I pre select the value of a dropdown when the value is retrieved from a webservice?

后端 未结 2 626
面向向阳花
面向向阳花 2021-01-06 09:19

Hello community been stuck on this one for a while...

Scenario: I have a dropdownlist which I pre-populate with values fetched from a service. Now

相关标签:
2条回答
  • 2021-01-06 09:38

    Give value to your model in select tag

    In your controller asign

    $scope.selectedValue = 'Step 1';  //your selected value, assign it in any way you wish
    $scope.stepsInvolved = response['stepsInvolved'];
    

    I am assuming your object is assigned to "response"

    <select ng-model='selectedValue' ng-options="item.value as item.label for item in stepsInvolved"></select>
    
    0 讨论(0)
  • 2021-01-06 09:40

    ngSelected is the directive of choice: http://plnkr.co/edit/dGJWityhYUZd9Ht6VgSJ?p=preview

    0 讨论(0)
提交回复
热议问题