However, while working with AngularJS dropdown, it was observed that the first option in the select dropdown is always empty. Have a look at the following example for better understanding.
Explanation and Correction: Generally, a list of options is transferred to ng-option. Those options are then displayed to the user in GUI format. However, when some value referenced by the ng-model doesn’t exist in the list transferred to the ng-option, then an empty option gets created in the GUI list, which can be seen above. The easiest way to correct this error is to reference a valid value from the ng-option list. The value referenced must be available on the list.
We can reference a valid value using this code. Here, i will be the index of the value that we want to reference.
Just add this code below the list to remove the empty option from the select. In the example given below, we are modifying the above example, in such a way that the empty option gets removed from the drop-down. We will set the value of i to 1. After doing this, the empty option will disappear and the default selected value will be set to C++.
- Include Bootstrap in AngularJS using ng-bootstrap
- AngularJS | ng-include Directive
- What is the best way to include CSS file? Why use @import?
- Why does sizeof(x++) not increment x in C?
- Why PHP script does not create a directory with 777 permissions ?
- Why does PHP 5.2+ disallow abstract static class methods ?
- Why does canvas.toDataURL() throws a security exception?
- Why does password boxes are smaller than text boxes in IE ?
- Why does SASS cache folder is created ?
- Why Transition properties does not work with display properties ?
- AngularJS | Select Boxes
- How to select first object in object in AngularJS?
- How to select an element by its class name in AngularJS ?
- How to make empty an array using AngularJS ?
- How to empty the content of an element using AngularJS ?
- Why do we use $rootScope.$broadcast in AngularJS?
- Why to check both isset() and !empty() function in PHP ?
- PHP | (Include and Require)
- How to include one CSS file in another?
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.