Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore.

15 St Margarets, NY 10033
(+381) 11 123 4567



Resetting the select value through your controller/services in AngularJS – JavaScript – SitePoint Forums

I am having a tough time figuring out why my select values will not reset once I load in new data to my template.

In my template, I have this code for the select:

<select ng-model="mySelect" ng-change="showSelectValue(mySelect)">
    <option ng-repeat="item in selectOptions" value="{{item.value}}" ng-selected="{{item.value}}">{{item.title}}</option>   

I set the values for select through my controller using this:

$scope.selectOptions = [
      {value: "EndTimeSoonest", title: "Ending Soonest"},
      {value: "StartTimeNewest", title: "Recently Added"},
      {value: "PricePlusShippingHighest", title: "Highest Priced"},
      {value: "PricePlusShippingLowest", title: "Lowest Priced"},
      {value: "Completed", title: "Completed - Most Recent"},
      {value: "CurrentPriceHighest", title: "Completed - Highest Price"}

After new data is loaded, the select value stays on the previously selected value. I am trying to get it to reset to the first item and nothing seems to work. I have tried both of these:

$rootScope.mySelect = $scope.selectOptions[0].value;



You can see the current version of the web app here: http://dev.sortsof.com to test it out yourself.

Credit: Source link

Previous Next
Test Caption
Test Description goes like this