Reputation: 12413
I'm trying to submit a form with AngularJS without use $http. I'm checking the form via Javascript, but not sure how to submit after the check is complete. Sample code looks like this:
AngularJS
app.directive('checkLoggedinSubmit', ['account_id', 'session', 'LoginModal',
function(account_id, session, LoginModal) {
return {
restrict : 'A',
link : function(scope, element, attrs) {
element.bind('submit', function(e) {
e.preventDefault();
//If not logged in, show logged in, otherwise subit
if (!account_id && !session.read('account_id')) {
LoginModal.show();
} else {
scope.$eval(attrs.checkLoggedinSubmit);
scope.$apply();
//Tried To use JQuery
//$(e.currentTarget).submit();
}
});
}
};
}]);
HTML Form
<form role="form" enctype="multipart/form-data" method="post" action="/file/submit" class="well" style="padding: 0px 20px 20px;" check-loggedin-submit >
<div class="form-group">
<input type="file" name="my_file" />
</div>
<div class="form-group">
<input type="submit" class="btn btn-success" />
</div>
</form>
I tried to have JQuery submit the form, but threw errors. Anyone now how to solve this?
Upvotes: 0
Views: 248
Reputation: 164
better way to submit form in angular is using "ng-sbmit"
you can use something like ng-submit="functionHandlingSubmitTask()"
you can look into given link to
http://learnwebtutorials.com/angularjs-tutorial-submitting-form-ng-submit
Upvotes: 2
Reputation: 511
try it:
<input type="submit" data-ng-click="save(input) class="btn btn-success" />
save is the JQuery method name and input is params.
Upvotes: 0