Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ng-select gives only string, but I want an integer

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).

like image 311
Nishchit Avatar asked Nov 06 '13 10:11

Nishchit


1 Answers

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)

like image 131
Trak Avatar answered Sep 22 '22 02:09

Trak