javascript - Form with lots of controls with interaction between them. Cleaner approach than $scope.$watch? -
i building angular app , form has 15 controls. it’s finance application. please don’t suggest break down page etc.
some of controls depend on each other. there 5 input controls (lets call them source controls), of can change, , impact 1 or more of 5 other controls (lets call them dest controls). way have structured have $scope.$watch on each of 5 source variables , in each watch function have code decide of 5 dest variables updated , update them. example of 1 of watches shows below.
$scope.$watch('money.price',function(newval,oldval) { if(newval != oldval) { if($scope.money.quantity != undefined) { updateprincipal($scope) updatefees($scope); $scope.money.net = $scope.money.principal + $scope.money.fee } } });
i don’t find elegant. there better / cleaner way ? (the form little more complex in future i.e. 2-3 more dependency fields not more that).
assuming input controls have ng-model attached them, recommend adding ng-change each input form, can use same function update of scope bindings @ once
Comments
Post a Comment