Kunal Gadhia
Kunal Gadhia

Reputation: 360

Unable to set value in ng-model after arithmetic calculation

I am creating a filter where user can select a location for property around him on basis of parameters & will select multiple things & based on that I am performing arithmetic calculation to find minimum budget & maximum budget, but when I am trying to put value (i.e after arithmetic calculation) based on state parameters & filter parameters. I am unable to set value, so can anyone let me know where I am getting wrong.I am getting the proper value in my consoles

My code is as follows :

Code in My Controller JS:

var minimumBudget = $stateParams.locationMinBudget * $stateParams.propertyDetails;
var maximumBudget = $stateParams.locationMaxBudget * $stateParams.propertyDetails;

console.log("Min Budget :%O", minimumBudget);
console.log("Max Budget :%O", maximumBudget);
$scope.minBudget = minimumBudget;
$scope.maxBudget = maximumBudget;

HTML :

<div class="form-group">
                        <select id="minBudget" class="form-control" ng-model="minBudget" required="required">
                            <option value="">Min Budget</option>
                            <option ng-repeat="minBudgetObject in minBudgetList" value="{{minBudgetObject.price}}" >&#8377; {{minBudgetObject.description}}</option>
                        </select>
 </div>
 <div class="form-group">                            
                        <select id="maxBudget" class="form-control" ng-model="maxBudget" required="required">
                            <option value="">Max Budget</option>
                            <option ng-repeat="maxBudgetObject in maxBudgetList" value="{{maxBudgetObject.price}}" >&#8377; {{maxBudgetObject.description}}</option>
                        </select>
</div>

So when I did the same thing the other way without arithmetic calculation, this thing works well. But not getting what is wrong here.

Any help is appreciated.

Upvotes: 0

Views: 66

Answers (1)

user93
user93

Reputation: 1866

By default $stateParams.propertyDetails is string when you do ng-repeat it repeats over each character and it. But when you do arithmetic it becomes number and it is unable to repeat over it.

For solving it both minimumBudget and maximumBudget should be an array

Upvotes: 1

Related Questions