AngularJS ng-selected 指令
定义和用法
ng-selected
指令设置 <select>
列表中 <option>
元素的 selected
属性。
如果 ng-selected
属性内的表达式返回 true
,则将选择该选项。
ng-selected
指令是能够在 ture da false 之间转换值所必需的。在 HTML 中,不能将 selected 属性设置为 false(selected 属性的存在会使元素被选中,无论其值如何)。
Example
Set the selected attribute to true:
Please click here to select BMW as your favorite car:
<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>
Syntax
<option ng-selected="expression</option>
Affected <option>
Element Support.
Parameters
Parameters | Description |
---|---|
expression | If it returns true, then the expression of the selected attribute of the element will be set. |