AngularJS | ng-selected Directive Last Updated : 01 Aug, 2024 Comments Improve Suggest changes Like Article Like Report 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 displayed otherwise not displayed. Syntax:<element ng-selected="expression"> Contents... </element>Parameter value:expression: It is used for setting the element's selected attribute if it returns true.Example: This example uses the ng-selected Directive to display the selected element. HTML <!DOCTYPE html> <html> <head> <title>ng-selected Directive</title> <script src= "https://ajax.googleapis.com/ajax/libs/angularjs/1.4.2/angular.min.js"> </script> </head> <body ng-app style="text-align:center"> <h1 style="color:green">GeeksforGeeks</h1> <h3>ng-selected Directive</h3> <p>Check to select default value:</p> <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:Example 2: This example describes the use of the ng-selected Directive in AngularJS by disabling the checkbox & ng-selected option. HTML <!DOCTYPE html> <html> <head> <title>ng-selected Directive</title> <script src= "https://ajax.googleapis.com/ajax/libs/angularjs/1.4.2/angular.min.js"> </script> </head> <body ng-app style="text-align:center"> <h1 style="color:green">GeeksforGeeks</h1> <h3>ng-selected Directive</h3> Check to select default value: <input type="checkbox" disabled ng-model="sort"> <br><br> <select name="geek" > <option value="1" >Merge sort</option> <option value="2" ng-selected="sort" disabled> Quick sort </option> <option value="3">Bubble sort</option> <option value="4">Insertion sort</option> </select> </body> </html> Output: Comment More infoAdvertise with us Next Article AngularJS | ng-selected Directive V Vishal Chaudhary 2 Follow Improve Article Tags : Web Technologies AngularJS AngularJS-Directives Similar Reads AngularJS ng-paste Directive The ng-paste Directive in AngularJS is used to specify custom behavior functions when the text in input fields is pasted into an HTML element. It can be used to call a function that will be triggered when the text is pasted into the input field. It is supported by <input>, <select> and 2 min read AngularJS ng-value Directive The ng-value Directive in AngularJS is used to specify the value of an input element. This directive can be used to achieve the one-way binding for the given expression to an input element, especially when the ng-model directive is not used for that specific element. It is supported by <input> 2 min read AngularJS ng-show Directive The ng-show Directive in AngluarJS is used to show or hide the specified HTML element. If the given expression in the ng-show attribute is true then the HTML element will display otherwise it hides the HTML element. It is supported by all HTML elements. Syntax: <element ng-show="expression"> C 2 min read AngularJS ng-switch Directive The ng-switch Directive in AngularJS is used to specify the condition to show/hide the child elements in HTML DOM. The HTML element will be displayed only if the expression inside the ng-switch directive returns true otherwise it will be hidden. It is supported by all HTML elements. Syntax: <elem 2 min read AngularJS ng-readonly Directive The ng-readonly Directive in AngularJS is used to specify the readonly attribute of an HTML element. The HTML element will be readonly only if the expression inside the ng-readonly directive returns true. The ng-readonly directive is required to change the value between true and false. In case, if t 2 min read Like