Alex Kumbhani Alex Kumbhani - 26 days ago 17
HTML Question

How should I set default option in angular with option?

I am using angular JS select with option like

<select class="form-control" ng-model="recureAdata" id="recure" ng-change="recureidChange()">
<option ng-value="0">Never</option>
<option ng-value="1">Every One Week</option>
<option ng-value="2">Every Two Week</option>
<option ng-value="3">Every Three Week</option>
<option ng-value="4">Every Four Week</option>
</select>


In this I have use many options and now I want to set default option of
Never
. How should I do?

Answer

You can use ng-init

<body data-ng-app="myApp">
 <select  ng-init="recureAdata='Never'" class="form-control" ng-model="recureAdata" id="recure" ng-change="recureidChange()">
    <option ng-value="0">Never</option>
    <option ng-value="1">Every One Week</option>
    <option ng-value="2">Every Two Week</option>
    <option ng-value="3">Every Three Week</option>
    <option ng-value="4">Every Four Week</option>
</select>
</body>

DEMO

Comments