Galdor
Galdor

Reputation: 1985

do a plain old form submit with angular

I want to do a plain old form submit within my angular app, e.g. with this code:

<form method="post" action="http://other-server/">
  <input name="something"
         value="somevalue"/>
  <button name="submit" type="submit">Submit</button>
</form>

So I put this into my components template, but nothing is submitted when I push the button.

The reason why I want this is because http://other-server/ does not send any Access-Control-Allow-Origin headers, so I cannot process the response in javascript.

Upvotes: 2

Views: 858

Answers (2)

Amirhossein Mehrvarzi
Amirhossein Mehrvarzi

Reputation: 18974

You can do it like below:

<form #form action='http://other-server/' method='post'>
    <input name="something"
     value="somevalue"/>
    <button type="submit" (click)="form.submit()">Submit</button>
</form>

Upvotes: 0

maafk
maafk

Reputation: 6896

MikeOne is correct.

Add ngNoForm to your form

<form ngNoForm method="post" action="http://other-server/">
  <input name="something"
         value="somevalue"/>
  <button name="submit" type="submit">Submit</button>
</form>

Upvotes: 5

Related Questions