使用ng-submit
我有一个表单提交回调,即submitFN
。有2个按钮:无法通过单个按钮触发在angularJS中提交
- 资助我的创业!
- 复位
我理想的输出上点击复位按钮,输入字段得到0与上点击“我的基金启动”它显示一个警告。如何实现这一目标?
问题: 这两个按钮都触发submitFN。无法重置。
代码:
<!DOCTYPE html>
<html>
<head>
<title></title>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.js">
</script>
<script>
var mainApp = angular.module("mainApp", []);
mainApp.controller('startUpController', function($scope) {
$scope.funding = {
startingEstimate: 0
};
$scope.calculate = function() {
$scope.funding.needed = $scope.funding.startingEstimate * 10;
};
$scope.submitFN = function() {
window.alert('Go and find more customers.')
}
$scope.resetFN = function() {
$scope.startingEstimate = 0;
}
});
</script>
</head>
<body>
<div ng-app='mainApp'>
<form ng-submit="submitFN()" ng-controller="startUpController">
Starting: <input type="text" ng-change="calculate()" ng-model="funding.startingEstimate"/>
Recommended: {{funding.needed}}
<button>Fund my startup!</button>
<button ng-click="resetFN()">Reset</button>
</form>
</div>
</body>
</html>
我完全新手angularJS任何帮助是非常可观的。提前致谢。
UPDATE 一个代码,我尝试:
<!DOCTYPE html>
<html>
<head>
<title></title>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.js">
</script>
<script>
var mainApp = angular.module("mainApp", []);
mainApp.controller('startUpController', function($scope) {
$scope.funding = {
startingEstimate: 0
};
$scope.calculate = function() {
$scope.funding.needed = $scope.funding.startingEstimate * 10;
};
$scope.submitFN = function() {
window.alert('Go and find more customers.')
}
$scope.resetFN = function() {
$scope.startingEstimate = 0;
}
});
</script>
</head>
<body>
<div ng-app='mainApp'>
<form ng-submit="submitFN()" ng-controller="startUpController">
Starting: <input type="text" ng-change="calculate()" ng-model="funding.startingEstimate"/>
Recommended: {{funding.needed}}
<button>Fund my startup!</button>
<button type = "button" ng-click="resetFN()">Reset</button>
</form>
</div>
</body>
</html>
嗨@pankaj,检查我的代码在更新的问题。我试着说你的话。但是现在点击复位不起作用。 – Ayan
看看更新的答案请 –