本文介绍了ng-select只给出字符串,但是我想要一个整数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我的有角html文件代码.在我的mongo数据库中,将 frequencyType
添加为 frequencyType ="1"
,但是我要 frequencyType = NumberInt(1);
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>
我进入数据库 frequencyType ="1"
,但是我想要 frequencyType = NumberInt(1)
.
I get in my database frequencyType = "1"
but I want frequencyType = NumberInt(1)
.
推荐答案
我建议您尝试使用 indexOf
.
JS
function MyCtrl($scope) {
$scope.values = ["Daily","Weekly","Monthly","Yearly"];
$scope.selectedItem = 0;
}
HTML
<div ng-app ng-controller="MyCtrl">
<select ng-model="selectedItem" ng-options="values.indexOf(selectedItem) as selectedItem for selectedItem in values"></select>
selectedItem: {{selectedItem}}
</div>
演示
因此发送到mongoDB $ scope.selectedItem
值
So send to mongoDB $scope.selectedItem
value
这篇关于ng-select只给出字符串,但是我想要一个整数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!