angularjs - How to set a selected option of a dropdown list control using angular JS -


i using angular js , need set selected option of dropdown list control using angular js. forgive me if ridiculous new angular js

here dropdown list control of html

 <select ng-required="item.id==8 && item.quantity > 0" name="postervariants"    ng-show="item.id==8" ng-model="item.selectedvariant"     ng-change="calculateservicessubtotal(item)"    ng-options="v.name v in variants | filter:{type:2}">   </select> 

after gets populated

 <select ng-options="v.name v in variants | filter:{type:2}" ng-change="calculateservicessubtotal(item)" ng-model="item.selectedvariant" ng-show="item.id==8" name="postervariants" ng-required="item.id==8 &amp;&amp; item.quantity &gt; 0" class="ng-pristine ng-valid ng-valid-required">     <option value="?" selected="selected"></option>     <option value="0">set of 6 traits</option>     <option value="1">5 complete sets</option> </select> 

how can set control value="0" selected?

i hope understand question, ng-model directive creates two-way binding between selected item in control , value of item.selectedvariant. means changing item.selectedvariant in javascript, or changing value in control, updates other. if item.selectedvariant has value of 0, item should selected.

if variants array of objects, item.selectedvariant must set 1 of objects. not know information have in scope, here's example:

js:

$scope.options = [{ name: "a", id: 1 }, { name: "b", id: 2 }]; $scope.selectedoption = $scope.options[1]; 

html:

<select data-ng-options="o.name o in options" data-ng-model="selectedoption"></select> 

this leave "b" item selected.


Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

css - Firefox for ubuntu renders wrong colors -