Home >Web Front-end >JS Tutorial >How do you create dynamic dropdown lists in AngularJS using ng-options?

How do you create dynamic dropdown lists in AngularJS using ng-options?

Linda Hamilton
Linda HamiltonOriginal
2024-11-09 00:54:021022browse

How do you create dynamic dropdown lists in AngularJS using ng-options?

Working with Select Using AngularJS's ng-options

In AngularJS, the ng-options directive allows you to dynamically generate

<select ng-model="selectedItem" ng-options="item.id as item.title for item in items">

Selecting a Default Option

To select a specific option by default, use the ng-init directive:

<select ng-model="selectedItem" ng-init="selectedItem = items[1]" ng-options="item.id as item.title for item in items">

Customizing the Default Option

By adding a custom