U
U
ut20102014-09-08 17:11:15
Domain Name System
ut2010, 2014-09-08 17:11:15

How can you dynamically calculate the product of the values ​​of two inputs and insert them into the third one?

This is what
index.html comes out with

<div ng-controller="TestCtrl">
   <input type="text" ng-model="w"/>
   <input type="text" ng-model="h"/>
   <input type="text" ng-model="s" />
   <p>Площадь = {{s}}</p>
</div>

controller.js
function TestCtrl($scope){
    $scope.w = 2;
    $scope.h = 3;
    $scope.s = $scope.w+$scope.h;
}

It is calculated only when the page is loaded, once, but it needs to be updated when w and h change.
Here is the final solution: http://codepen.io/ut2010/pen/eAFgb suggested by AMar4enko

Answer the question

In order to leave comments, you need to log in

1 answer(s)
_
_ _, 2014-09-08
@ut2010

$scope.$watch('[w,h]', function(values){
  var w = values[0] || 0, h = values[1] || 0;
  $scope.s = w*h;
}, true);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question