Skip to content
Related Articles

Related Articles

Improve Article

AngularJS | ng-selected Directive

  • Last Updated : 28 Mar, 2019

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.


<element ng-selected="expression"> Contents... </element> 

Example: This example uses ng-selected Directive to display the selected element.

<!DOCTYPE html>
    <title>ng-selected Directive</title>
    <script src=
<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">
    <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>

Before checked the checkbox:
After checked the checkbox:

My Personal Notes arrow_drop_up
Recommended Articles
Page :