Reputation: 614
I have an ng-options select in my front-end application like so:
<select ng-model="calc.details.option" name="royaltyOption"
ng-options="obj.label for obj in royaltyOptions track by obj.value">
</select>
In the page's controller:
$scope.royaltyOptions = [{ "value": 6.25, "label": "Yes" }, { "value": 0.00, "label": "No" }];
The desired behavior is to send the numeric value to the backend once the form is submitted of either 0.00
or 6.25
. What I get instead is NaN
- not a number. When I console.log()
what is actually being sent back I get [object Object]"
.
How do I get the value sent to be a number? I feel like I have followed the exact syntax mentioned in documentation and other StackOverflow/forum discussions I have found on the web.
Upvotes: 1
Views: 79
Reputation: 4655
You're passing object. You can use in controller. Here is something from the doc
Do not use select as and track by in the same expression. They are not designed to work together.
You should use it like
ng-options="obj.label for obj in royaltyOptions track by obj.value">
In controller
console.log($scope.calc.details.option.value)
Upvotes: 2