javascript - AngularJS - Trouble setting default drop down menu option -


i new angularjs. right have following 2 filters applied on e-commerce site:

                         <div ng-show="user.shipmethod != null && shippers && ordershipaddress.addressname != 'big'" " ng-class="{'view-form-select': !currentorder.lineitems[0].shippername, '': currentorder.lineitems[0].shippername }">                                 <label ng-class="{required: !currentorder.ismultipleship() && user.shipmethod != null}" ng-show="currentorder.lineitems[0].shippername || !currentorder.ismultipleship() && user.shipmethod != null">{{('shipping' | r) + ' method' | xlat}}</label>                                 <select class="form-control" ng-change="updateshipper()" name="shipmethod"                                         ng-model="currentorder.lineitems[0].shippername"                                         ng-show="user.shipmethod.shipperselectiontype == 'userdropdown'"                                         ng-options="shipper.name (shipper.name + ' ' + (shipper.shippingrate.price | currency | xlat)) shipper in shippers | filter: { name: '!pick-up @ big'}"                                         ng-required="!currentorder.ismultipleship() && user.shipmethod != null" >                                      <option value=""></option>                                 </select>                                 <i class="fa fa-truck"></i>                             </div>                              <div ng-show="user.shipmethod != null && shippers && ordershipaddress.addressname == 'big'" ng-class="{'view-form-select': !currentorder.lineitems[0].shippername, '': currentorder.lineitems[0].shippername }">                                 <label ng-class="{required: !currentorder.ismultipleship() && user.shipmethod != null}" ng-show="currentorder.lineitems[0].shippername || !currentorder.ismultipleship() && user.shipmethod != null">{{('shipping' | r) + ' method' | xlat}}</label>                                 <select class="form-control" ng-change="updateshipper()" name="shipmethod"                                         ng-model="currentorder.lineitems[0].shippername"                                         ng-show="user.shipmethod.shipperselectiontype == 'userdropdown'"                                         ng-options="shipper.name (shipper.name + ' ' + (shipper.shippingrate.price | currency | xlat)) shipper in shippers | filter: { name: 'pick-up @ big'}"                                         ng-required="!currentorder.ismultipleship() && user.shipmethod != null" >                                     <option value=""></option>                                 </select>                                 <i class="fa fa-truck"></i>                             </div>                         </div> 

my controller located here: https://big.four51ordercloud.com/test0530/js/directives/ordershipping.js

in controller, came set default drop down menu option, not sure put in updateshipper() function. want default if there 1 option in drop down menu. right now, user has manually select if there 1 option, but, other options populate, depending upon if condition other filter met. first filter see yield multiple options in drop down, while second one, yield 1 option - "pick-up @ big" option.

$scope.currentorder.lineitems[0].shippername = $scope.shippers[0]; 

use ng-model set default value list item. whenever select item ng-model variable have set upadte

see example

<select  ng-options="p p in animal"             ng-model="selectedanimal"></select> 

Comments

Popular posts from this blog

facebook - android ACTION_SEND to share with specific application only -

python - Creating a new virtualenv gives a permissions error -

javascript - cocos2d-js draw circle not instantly -