简体   繁体   中英

AngularJS set select option from db

I have been able to get the default value selected using the below. However, I am not sure how to set the value to the one previously selcted by the user for the object they are reviewing. If the default value matches their selection, then great it is fine. However, if the default is different how can I make sure the select is showing the item that that they picked? For example, they have selected item [2] in the drop down not the default [0]

<div class="container-fluid">
select ng-init="part.PartType = partTypes[0]" class="form-control" data-ng-model="part.PartType" data-ng-options="p for p in partTypes" required></select>
</div>

I wouldn't doubt there was something obvious I am missing. I am just not sure what to set in order to display the previously selected value that is being returned from the db.

Any suggestions would be greatly appreciated.

Thanks, S.

Angular.js有2种方式,因为在变量中您应该可以在控制器中进行设置

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM