I have a dropdown list with city names, Dropdown1: Boston, NY, LA
Upon selected value from the dropdown list, the order of the value to be shown in the dropdown box should be changed.
If dropdown1 selected value = Boston, Then dropdown2: somethingrelated to Boston
In my code,
- When I selected Boston, it does change for the first time
- when I select another city and selected Boston again and a value for it.
- When I select Boston back, the dropdown box doesn't get repopulated.
Here's the code:
## RAILS VIEW
.ui-select-input-group ng-if="statePlans.length > 0"
select.form-control.ui-select-toggle ng-model="planOne" ng-options="plan.name for plan in statePlans track by plan.id" ng-change="changePlan()"
option[value=""]
| Select a Plan
## Javascript
for (let i = 0; i < $scope.allPlans.length; i++) {
if ($scope.allPlans[i].state == $scope.user.state) {
statePlans.push($scope.allPlans[i]);
}
}
$scope.statePlans = statePlans;
if ($scope.user.state == 'Boston') {
var planOne = $scope.statePlans.filter(function(item) {
return item.name === 'Boston City Tours';
})[0];
$scope.planOne = planOne;
}