This is my angular html file code. In my mongo database frequencyType
added as frequencyType = "1"
, but I want frequencyType = NumberInt(1);
<div class="span4"> <select class="span12 combobox" ng-model="frequencyType" required> <option value="1">Daily</option> <option value="2">Weekly</option> <option value="3">Monthly</option> <option value="4">Yearly</option> </select> </div>
I get in my database frequencyType = "1"
but I want frequencyType = NumberInt(1)
.
There is an easier way:
Just use value*1
as your id, that will convert the string to int without changing the value... assuming the id is an integer.
so the result is>
<div ng-app ng-controller="MyCtrl"> <select ng-model="selectedItem" ng-options="selectedItem*1 as selectedItem for selectedItem in values"></select> selectedItem: {{selectedItem}} </div>
This will work in more cases, since indexOf is not available in objects, only in arrays. This solution works for objects with integers as keys (for example if some keys are missing, or if you use db ids)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With