javascript - How to have a default option in Angular.js select box -
i have searched google , can't find on this.
i have code.
<select ng-model="somethinghere" ng-options="option.value option.name option in options" ></select>
with data
options = [{ name: 'something cool', value: 'something-cool-value' }, { name: 'something else', value: 'something-else-value' }];
and output this.
<select ng-model="somethinghere" ng-options="option.value option.name option in options" class="ng-pristine ng-valid"> <option value="?" selected="selected"></option> <option value="0">something cool</option> <option value="1">something else</option> </select>
how possible set first option in data default value result this.
<select ng-model="somethinghere" ....> <option value="0" selected="selected">something cool</option> <option value="1">something else</option> </select>
you can use ng-init this
<select ng-init="somethinghere = options[0]" ng-model="somethinghere" ng-options="option.name option in options"> </select>
Comments
Post a Comment