Reputation: 4389
Is there any easy way to submit form using angularjs without angular ajax call or old school style by adding action="xxxx"
attribute to form?
An example would be a huge form where assigning model for each field is not an option or either sending it with ajax call as well, but since form got inside ng-app I can't find any other solution on how to submit it. Forgot to say, that adding action to all sorts of forms is bad idea as well(in my case).
I've tried combining it with jQuery, but I'm probably doing that worng as well.
<form name="ticketForm" method="post" enctype="multipart/form-data" ng-controller="TicketCtrl" ng-submit="submitForm()">
...
</form>
And script part would be:
var Ticket = angular.module('ticket', []);
Ticket.controller('TicketCtrl', ['$scope', function($scope)
{
$scope.submitForm = function()
{
$('form[name="ticketForm"]').submit();
};
}]);
The form is submited, but in console I see, that angular doesn't like it much,
Error: $apply already in progress
Upvotes: 1
Views: 4626
Reputation: 388316
I think it is leading to a recursive call(because since you are calling the submit on a jQuery wrapper object it will again call the form submit handler), try to call the submit method of the dom element instead
$('form[name="ticketForm"]')[0].submit();
Upvotes: 6