0

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?

0

3 Answers 3

2

From the Angular documenation:

ngSubmit
Enables binding angular expressions to onsubmit events.

Link here

Sign up to request clarification or add additional context in comments.

Comments

1

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.

Comments

1

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();
    }
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.