AngularJS | ng-selected Directive
The ng-selected Directive in AngularJS is used to specify the selected attribute of an HTML element. It can be used to select the default value specified on an HTML element. If the expression inside the ng-selected directive returns true then the selected option value will be display otherwise not display.
Syntax:
<element ng-selected="expression"> Contents... </element>
Example: This example uses ng-selected Directive to display the selected element.
<!DOCTYPE html> < html > < head > < title >ng-selected Directive</ title > < script src = </ script > </ head > < body ng-app style = "text-align:center" > < h1 style = "color:green" >GeeksforGeeks</ h1 > < h2 >ng-selected Directive</ h2 > Check to select default value: < input type = "checkbox" ng-model = "sort" > < br >< br > < select name = "geek" > < option value = "1" >Merge sort</ option > < option value = "2" ng-selected = "sort" >Quick sort</ option > < option value = "3" >Bubble sort</ option > < option value = "4" >Insertion sort</ option > </ select > </ body > </ html > |
Output:
Before checked the checkbox:
After checked the checkbox:
Recommended Posts:
- AngularJS | ng-app Directive
- AngularJS | ng-if Directive
- AngularJS | ng-jq Directive
- AngularJS | ng-src Directive
- AngularJS | ng-cut Directive
- AngularJS | ng-value Directive
- AngularJS | ng-csp Directive
- AngularJS | Directive
- AngularJS | ng-required Directive
- AngularJS | ng-paste Directive
- AngularJS | ng-srcset Directive
- AngularJS | ng-readonly Directive
- AngularJS | ng-blur Directive
- AngularJS | ng-bind Directive
- AngularJS | textarea Directive
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. 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.