0

You can find a Plunker demonstrating the Problem here: Plunker

I want to use nested forms in AngularJS. To do that it seems like ng-form is the way to go and i tried the following:

<form novalidate ng-submit="ctrl.form1()">
    <button type=submit>Form1</button>
    <ng-form novalidate ng-submit="ctrl.form2()">
        <button type=submit>Form2</button>  
    </ng-form>
</form>

While I expected the inner submit to execute the submit-action of the inner form, instead the method form1() is called everytime when i click either button.

Why does it behave like this and how can i achieve the expected result?

1 Answer 1

1

You can use one of the following two ways to specify what javascript method should be called when a form is submitted: * ngSubmit directive on the form element * ngClick directive on the first button or input field of type submit (input[type=submit])

Visit Angular Forms

    <form novalidate>
        <button type=submit ng-click="ctrl.form1()">Form1</button>
            <ng-form novalidate >
               <button type=submit ng-click="ctrl.form2()">Form2</button>  
            </ng-form>
    </form>

see working plunker here

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

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.