$scope赋值为';t工作-angularjs

$scope赋值为';t工作-angularjs,angularjs,angularjs-scope,Angularjs,Angularjs Scope,在我的代码中,我创建了一个重置按钮来清除表单。在重置时,我还希望清除一个依赖于该输入的值。在reset()函数中,$scope.funding.startingEstimate正确设置为零,但$scope.funding.needed不正确。此外,$watch scope函数不应该已经处理了吗?无论何时更改funding.startEstimate(因为它在$scope.reset函数中成功,建议的字段不应该也返回零,因为$watch函数调用computeneed,它将funding.start

在我的代码中,我创建了一个重置按钮来清除表单。在重置时,我还希望清除一个依赖于该输入的值。在reset()函数中,$scope.funding.startingEstimate正确设置为零,但$scope.funding.needed不正确。此外,$watch scope函数不应该已经处理了吗?无论何时更改funding.startEstimate(因为它在$scope.reset函数中成功,建议的字段不应该也返回零,因为$watch函数调用computeneed,它将funding.startingEstimate乘以10(0*10等于0)

请帮忙

下面是我的代码:

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>
app.controller('StartUpController',[“$scope”,函数($scope){
$scope.funding={startingEstimate:0};
$scope.computeNeeded=函数(){
console.log(“test2”)
$scope.funding.needed=$scope.funding.startingEstimate*10;
};
$scope.$watch('funding.startingEstimate',$scope.computeeded);
$scope.requestFunding=函数(){
window.alert(“对不起,请先找到更多的客户”);
};
$scope.reset=function(){
控制台日志(“测试”)
$scope.funding.startingEstimate=0;
$scope.funding.needed=0;
};
}]);
启动:
建议:{{需要资金}
申请资金
重置

当我告诉你你忘了在Angular中调用
reset()
方法时,你会很生气的。相反,你将按钮的
类型定义为
reset
,因此你得到了重置表单的基本HTML功能


我为您添加了
ng click

要添加到您的答案中,我不相信存在一个称为ng reset的角度指令,因此应该将其全部删除。同意。我从未见过
ng reset
指令。