如何从选择输入值中获取整数

时间:2016-12-16 17:54:01

标签: javascript angularjs drop-down-menu

我是AngularJS的新手,我尝试从select选项中获取整数。所以,我有

<select class="form-control" id="decimation" placeholder="1 or 8" ng-model="data.settings.decimation">
                     <option type="number" value="1" ng-click="deci_bool=0">1</option>
                     <option type="number" value="8" ng-click="deci_bool=1">8</option>
</select>

我希望将以下输入与选项值

绑定
<input ng-if="!deci_bool" type="number"  class="form-control" id="b_mesu" placeholder="Between 0 and {{data.settings.decimation + 96 }}" ng-model="data.settings.b_mesu" min="0" max="97" step="1" ng-click="b_mesu_ctrl" required>

但似乎data.settings.decimation + 96被串联为一个字符串。

我尝试在SO张贴后select标记

中添加此内容
ng-options="values.indexOf(data.settings.decimation) for data.settings.decimation in values"

但是我收到此错误消息

Error: [ngOptions:iexp] Expected expression in form of '_select_ (as _label_)? for (_key_,)?_value_ in _collection_'

有人可以帮忙吗?

2 个答案:

答案 0 :(得分:1)

--watch

JS:

<div ng-controller="testCtrl">
            <select class="form-control" id="decimation" placeholder="1 or 8" ng-model="decimation">
                     <option type="number" value="1" ng-click="deci_bool=0">1</option>
                     <option type="number" value="8" ng-click="deci_bool=1">8</option>
</select>

{{decimation}}<br/>

<input type="number" ng-model="b_mesu" ng-change="updateSelect()" min="0" max="97" step="1" ng-click="b_mesu_ctrl" required>

        </div>

答案 1 :(得分:1)

试试这个:placeholder="Between 0 and {{ (data.settings.decimation * 1)+78}}"
JSFiddle
附:很奇怪,但placeholder="Between 0 and {{ +data.settings.decimation +78}}"不起作用。