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.

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:
ngselected
After checked the checkbox:
ngselected




My Personal Notes arrow_drop_up
Recommended Articles
Page :