自动更新值

时间:2017-12-15 11:36:11

标签: angularjs

我有

 <input type="range" ng-init="overral=0" ng-model="overral"/> {{overral}}

 <input ng-model="value1" type="number" ng-init="value1=10" />
 <input ng-model="age1" type="number" ng-init="age1=30" />
 <input ng-model="postal1" type="number" ng-init="postal1=25" />

我需要更新&#34; overral&#34;以40为例:

value1 = valu21*40;
age1= age1*40;
postal1= postal1*40;

或我更新&#34; overral&#34;以80为例:

value1 = valu21*80;
age1= age1*80;
postal1= postal1*80;

但我需要在输入中自动更新

Edit1:

 <input type="range" ng-model="overral" ng-init="overral=0" /> {{overral}}

 <input ng-model="value1"  type="number" ng-value=10*overral />
 <input ng-model="age1"    type="number" ng-value=40*overral />
 <input ng-model="postal1" type="number" ng-value=25*overral />

它的工作,但我需要这个,因为我需要先看看原始值,然后用overral计算后如果高于0:

<input type="range" ng-model="overral" /> {{overral}}

<input ng-model="value1" type="number" ng-init="value1" ng-value=value1*overral /> 
<input ng-model="age1" type="number" ng-init="age1" ng-value=age1*overral /> 
<input ng-model="postal1" type="number" ng-init="postal1" ng-value=postal1*overral />

3 个答案:

答案 0 :(得分:1)

我认为这是您想要的,使用ng-value。按照最初的要求,没有控制器。

&#13;
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.0/angular.min.js"></script>
<div ng-app>

  <input type="range" ng-model="overral" /> {{overral}}

  <input ng-model="value1"  type="number" ng-value=10*overral />
  <input ng-model="age1"    type="number" ng-value=40*overral />
  <input ng-model="postal1" type="number" ng-value=25*overral />

</div>
&#13;
&#13;
&#13;

答案 1 :(得分:0)

控制器中的

: ` if($ scope.overral == 40){

$ scope.value1 = $ scope.value1 * 100;

$ scope.age1 = $ scope.age1 * 100;

$ scope.postal1 = $ scope.postal1 * 100;

} &#39; 在角度双向数据绑定中,所以你将直接更新html中的值

答案 2 :(得分:0)

根据需要保留您的输入值。 就像value1

一样