I'm very new to Angularjs and the MVVM model in general. I'm trying to build a calculator app that works the way an excell spreadsheet might. IE updating one cell causes all the dependent cells to also update.
So far my code looks like this
<div ng-app="">
<div ng-controller="calculations">
<input type="number" name="staff" ng-model="staff" id="staff" ng-change="change('C3')" />
<input type="hidden" name="budget" ng-model="budget" ng-change="change('C6')" placeholder="budget" />
<input type="text" name="total" ng-model="total" ng-change="change('C8')" />
</div>
and the Angular
function calculations($scope) {
$scope.change = function (cell) {
if (cell == 'C3') {
$scope.budget = $scope.staff * 35000;
}
};
}
What I don't know how to do is add a joining function that when cell = C6 (which it should $scope.budget is set in my first function) then $scope.total = $scope.budget / $scope.staff; and so on until all my fields have dynamic values. The idea is that I don't want to have to do a submit or click to begin the calculations, I want to do them on the fly which is why I chose angular because it's my understanding that this is what it does well. Thoughts?