0

While working on basic angular examples ng-click is not working as expected

the following is my html code :

<form ng-submit="requestFunding()" ng-controller="StartUpCalculator">
    Starting :
    <input ng-change='ComputeNeeded()' ng-model='funding.StartingEstimate'>Recommedation : {{needed}}
    <button>Fund me</button>
    <button ng-click="reset()">Reset</button>
</form>

Javascript code :

function StartUpCalculator($scope)
{
    $scope.funding = {
        StartingEstimate: 0
    };
    ComputeNeeded = function ()
    {
        $scope.needed = $scope.funding.StartingEstimate * 10;
    };

    $scope.requestFunding = function ()
    {
        window.alert("Whoa!");
    };
}

whenever i click Reset(reset()) button it executes requestFunding function

2 Answers 2

1

Thre is no $scope.reset() in controller. You are triggering the ng-submit by clciking the button.

You can change <button> to <button type="button"> so it won't be bound to form submit. By default any button in a form with no type, and no click handler to preventDefault(), will trigger submit, however type="button" will not.

You also need to change ComputeNeeded to $scope.ComputeNeeded if you want it to work with ng-change

Sign up to request clarification or add additional context in comments.

Comments

0

Because on ng-submit you are calling requestFunding. Add a new button and call requestFunding from there or else remove reset from form tag and place it putside.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.