Выполнение примера из книги AngularJS, почему нажатие кнопки Reset
приводит к оповещению, sorry, please get more customers.
?Разделительная кнопка Нажмите Поведение
Я хочу только alert
, когда нажимаем кнопку Fund my startup!
.
<html ng-app>
<body>
<script src=
"https://ajax.googleapis.com/ajax/libs/angularjs/1.0.1/angular.min.js">
</script>
<form ng-submit="requestFunding()" ng-controller="StartUpController">
Starting: <input ng-change="computeNeeded()" ng-model="startingEstimate">
Recommendation: {{needed}}
<button>Fund my startup!</button>
<button ng-click="reset()">Reset</button>
</form>
<script>
function StartUpController($scope) {
$scope.computeNeeded = function() {
$scope.needed= $scope.startingEstimate * 10;
};
$scope.requestFunding = function() {
window.alert("sorry, please get more customers.");
};
$scope.reset = function() {
$scope.startingEstimate = 0;
};
}
</script>
</body>
</html>
Почему поведение по умолчанию кнопки 'submit' вызывает' reset() '? –
Другой способ: кнопка сброса запускает отправку, потому что по умолчанию любая кнопка отправляется. – Tosh
В результате все нажатия кнопок (в области контроллера?), То есть 'submit', приведут к вызову' reset() ', если мы не используем' event.preventDefault() '? –