AngularJS ng-selectedDirective

AngularJS 参考手册AngularJS Reference Manual


AngularJS Example

Get the selected option:

Click the checkbox to select the BMW option:
<input type="checkbox" ng-model="mySel">

<p>My favorite car:</p>

<select>
<option>Volvo</option>
<option ng-selected="mySel">BMW</option>
<option>Ford</option>
</select>

Try it Yourself »

Definition and Usage

ng-selectedThe directive is used to set the selected attribute of the <option> element in a <select> list.

ng-selectedIf the expression in the attribute returns true, the option is selected.


Syntax

<option ng-selected="expression"></option>

This directive is supported by the <option> element.


Parameter Value

Value Description
expression If the expression is true, the option is selected.

AngularJS 参考手册AngularJS Reference Manual

Other Extensions