一尘不染

ng-select仅给出字符串,但我要整数

angularjs

这是我的html文件代码。在我的mongo数据库中frequencyType添加为frequencyType = "1"
但我想要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)


阅读 213

收藏
2020-07-04

共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>

演示版 **[Fiddle](http://jsfiddle.net/EyBVN/38/)**

因此发送给mongoDB的$scope.selectedItem价值

2020-07-04