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
Release: 2024-11-09 00:54:02
Original
1011 people have browsed it

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">
Copy after login

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">
Copy after login

Customizing the Default Option

By adding a custom