Suresh PMS Suresh PMS - 6 months ago 15
Javascript Question

angular - passing ngmodel bound to an element to a function bound to another element

I have a requirement of passing a value entered in an

input[type="text"]
element to a function
calculate()
which is bound to another element. So, whenever the value in the input field changes, the calculated values should reflect in the
Result
.

If it could be done in any other way, please let me know. Appreciated.

My Html goes as follows:

<tr>
<td>Points</td>
<td ng-repeat="score in player.scores ">
<input type="text" ng-value="{{score.stroke}}" ng-model="???????"/>
</td>
</tr>
<tr>
<td>Result</td>
<td ng-repeat="param in cellParams >{{calculate(??????)}}</td>
</tr>

Answer

I have achieved this using $watch().

$scope.$watch('player', function(newVal, oldVal) { 
      calculate(newValue);
} 

Got this answer from Alpesh's hint.

Comments