I want to update model value from custom directive with attribute value. Let's imagine that I have 4 numbers. I want to do the following:
- Sum first two numbers (1+2)
- Sum second two numbers (3+4)
- Sum both sums (sum1+sum2) - cascade sum
Formula is expressed in attribute value of custom directive. I'm not so experienced in Angular and have some partial working solutions, but I think I'm going in the wrong direction, so I'll post code without custom directive.
Here is the code for which i'm trying to build custom directive, what would be the best approach for writing that directive (formula)?
EDIT: input fields with formula directive will be read-only, and they only have one purpose - to recalculate values from other fields depending on the formula.
<!DOCTYPE html>
<html ng-app>
<head>
<script data-require="angular.js@*" data-semver="1.4.0-beta.5" src="https://code.angularjs.org/1.4.0-beta.5/angular.js"></script>
<link rel="stylesheet" href="style.css" />
<script src="script.js"></script>
</head>
<body>
<h1>Cascade sum example</h1>
<input ng-model="A1" type="number">
<input ng-model="A2" type="number">
<input ng-model="A3" type="number">
<input ng-model="A4" type="number">
<input ng-model="A5" type="number" formula="A1+A2" readonly>
<input ng-model="A6" type="number" formula="A3+A4" readonly>
<input ng-model="A7" type="number" formula="A5+A6" readonly>
</body>
</html>