In my code I am creating a reset button to wipe a form clean. with the reset I also want a value that's dependent on that input to also clear. Within the reset() function, $scope.funding.startingEstimate is correctly set to zero, however $scope.funding.needed is not. Furthermore, shouldn't the $watch scope function take care of that already? Anytime the funding.startEstimate is changed (as it is successfully in the $scope.reset function, shouldn't the recommended field also return to zero because the $watch function calls computeNeeded which multiplies funding.startingEstimate by 10 (with 0*10 equaling 0).
Please help.
Below is my code:
app.js
app.controller('StartUpController',["$scope", function($scope){
$scope.funding = {startingEstimate:0};
$scope.computeNeeded=function(){
console.log("test2")
$scope.funding.needed = $scope.funding.startingEstimate * 10;
};
$scope.$watch('funding.startingEstimate', $scope.computeNeeded);
$scope.requestFunding=function(){
window.alert("Sorry, please get more customers first");
};
$scope.reset=function(){
console.log("test")
$scope.funding.startingEstimate = 0;
$scope.funding.needed = 0;
};
}]);
<form ng-controller="StartUpController" ng-submit="requestFunding()" ng-reset="reset()">
Starting: <input ng-model="funding.startingEstimate" >
Recommendation:{{funding.needed}}
<button type="submit" class="btn btn-primary">Request Funding </button>
<button type="reset" class="btn btn-danger" >Reset</button>
</form>