Angular 2 form not sending action request when submitting

10,289

You can do:

<button type="submit" (click)="f.submit()">Login</button>

or use the ngNoForm attribute in the form tag as @Thierry Templier suggested here:

How to submit form to server in Angular2

Share:
10,289
VPusher
Author by

VPusher

I do stuff.

Updated on June 13, 2022

Comments

  • VPusher
    VPusher about 2 years

    I'm trying to make a simple login form work with an action attribute. The issue here is the request to /login is never sent. Copying and pasting the form in the DOM through the dev tools make the copied one work. Angular seems to prevent the default behavior of the form.

    Here is my login form component, very basic:

    @Component({
      selector: 'my-app',
      template: `
        <form #f="ngForm" action="/login" method="POST">
          Username: <input type="text"required>
          <br/>
          Password: <input  type="password" required>
          <br/>  
          <button type="submit">Login</button>
        </form>
      `,
      directives: [FORM_DIRECTIVES]
    })
    

    I also tried to return true/false in the ngSubmit directive's handler but it does not work too.

    Here is a plunker illustrating the issue.

    Anyone knows how to tell angular to submit the form with the action request ?

    angular.2.0.0-Beta.1