AngularJSng-selectedディレクティブ


selected属性をtrueに設定します

Click here to select BMW as your favorite car:
<input type="checkbox" ng-model="mySel">

<p>My Favourite car:</p>

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

定義と使用法

ng-selectedディレクティブは、<select>リストの<option>要素の選択された属性を設定します

ng-selected 属性内の式がtrueを返す場合、このオプションが選択されます。

ディレクティブは、との間ng-selected値をシフトできるようにするために必要です。HTMLでは、属性をに設定することはできません(選択された属性が存在すると、その値に関係なく、要素が選択されます)。truefalseselectedfalse


構文

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

<option>要素でサポートされています。


パラメータ値

Value Description
expression An expression that will set the element's selected attribute if it returns true.