Table of Contents
Working with Select Using AngularJS's ng-options
Generating Options from an Array
Example
Selecting a Default Option
Customizing the Default Option
Hiding the Default Option After Selection
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?

Nov 09, 2024 am 12:54 AM

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