How to reset/change select value in AngularJS after new data is loaded into web app?

19 views
Skip to first unread message

Barnaby Farnsworth

unread,
Aug 15, 2017, 1:54:47 PM8/15/17
to Angular and AngularJS discussion
I am attempting to troubleshoot why my select option value in my web app won't change after I load new data. 

This is currently the select code in my web app:

<select ng-model="mySelect" ng-change="showSelectValue(mySelect)" ng-options="item.value as item.title for item in selectOptions" no-dirty-check="">  </select>

My controller processes the options with this code:

$scope.init = function() {
  $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"}
 
];
};
 
$scope
.init();

I am loading a series of data based of the user selecting items from the drop down menu. However, if they go to load a new search or new data, the last selected item in the select remains chosen, but the correct values are being passed.

You can see the proof of concept here: http://dev.sortsof.com 

Any ideas on how I can get the select to reset after a new search or loading new data?

Tito

unread,
Aug 15, 2017, 7:11:11 PM8/15/17
to Angular and AngularJS discussion
I think you will have to reload the drop down anew by calling Init again.

Barnaby Farnsworth

unread,
Aug 15, 2017, 9:11:50 PM8/15/17
to Angular and AngularJS discussion
I tried that and didn't have any luck.

Sander Elias

unread,
Aug 16, 2017, 12:03:49 AM8/16/17
to Angular and AngularJS discussion
Hi Barnaby,

Did you try setting `mySelect = undefined` in your controller?

Regards
Sander
Reply all
Reply to author
Forward
0 new messages