Infor Mat
Infor Mat

Reputation: 117

Angular equivalent of jQuery submit()

Using jQuery I can do something like this:

$('#submitButton').on('click', function(event) {
    event.preventDefault();
    var result = confirm('Are you sure?');
    if (result) {
        $('#submitForm').submit();
    }
});

Before submit I need confirmation from user and then post data to server with reload (redirect) page. In what way can I do this in Angular?

Upvotes: 0

Views: 191

Answers (3)

Infor Mat
Infor Mat

Reputation: 117

Thanks for suggestions. In this case solution can be:

$scope.submitMyForm = function() {
    var result = confirm('Are you sure?');
    if (result) {
        var finishForm = document.getElementById('finishForm');
        finishForm.setAttribute("action", "/some-url");
        finishForm.submit();
    }
}

Upvotes: 1

Arturo Montaño
Arturo Montaño

Reputation: 121

In angular you are not supposed to submit forms that way, you are supposed to have model variables and use them with $http in order to interact with your server via asynchronous calls, however, angular.js uses jquery and even includes a lite version of it, so, if you must send your form in the traditional way, you can still do so via jquery.

Upvotes: 1

Fabian N.
Fabian N.

Reputation: 3856

From the Angular documenation:

ngSubmit
Enables binding angular expressions to onsubmit events.

Link here

Upvotes: 2

Related Questions