简体   繁体   中英

Can I pre-select a value in a <select> populated by AngularJS?

I have the following code:

<select
   data-ng-disabled="modal.action=='delete'"
   data-ng-model="modal.formData.contentTypeId"
   data-ng-options="item.id as item.name for item in option.contentTypes">
</select>

The code populates a select box with different contentTypes. However when the select box appears then initially nothing is selected and it is blank.

Is there a way I could have it select the first of the contentTypes as a default ?

You can set default value in your controller

$scope.modal.formData.contentTypeId= option.contentTypes[0].id

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