有沒有一種方法可以在不使用異步調用的情況下使用AngularJs提交表單? 我希望它的行爲就好像我在常規HTML表單上按下提交按鈕一樣。AngularJS表單提交和重定向
HTML:
<div ng-controller="myController">
<form id="myForm">
<input ng-model="handle">
<button ng-click="submitForm($event)">Submit</button>
</form>
</div>
目前我做它像我下面。問題是,我仍然在同一頁面上,然後我必須重定向。但下一頁的內容取決於表單提交,我寧願不將表單提交的內容存儲在會話中。
angular.module('myApp').controller('myController', ['$scope', function($scope) {
$scope.handle;
$scope.submitForm = function($event) {
$event.preventdefault();
var modifiedHandle= $scope.handle + 'handle';
$http({
url: '/submit',
method: 'POST',
data: {'handle': modifiedHandle }
}).then(function(response){
$window.location.href = '/success';
//The problem of this approach is that the contents of '/success' depends on the form input.
//I'd rather not have to flash the submitted data to a session. Is there a pure AngularJs way to do this?
}, function(data, status){});
}
}]);