21

The code given below is not working in my angular html file but if i use this code individually in an html file it works i don't know what i am doing wrong this is just a simple form .

<form action='https://easypaystg.easypaisa.com.pk/easypay/Index.jsf' method='post'>
    <input  name='storeId' value='4950'>
    <input  name='amount' value='1000'>
    <input  name='postBackURL' value='https://easypaystg.easypaisa.com.pk/easypay/Confirm.jsf'>
    <input  name='orderRefNum' value='123113'>
    <input  name='merchantHashedReq' value='6ohsP8x3PpiaI4oNirWGwjVkyMLP4CbzcH6pZwvu9SViOzx9nLxyR/TtJhwFrxBU686Wf1z22G+TBxuo5QkSscuXp266qQWx8AbGWnLXxG79LHt+5VlD+lH2JkjKO997adwVHH6mGNm8ldtAKkRyf/E92QF5PwhWMjq8i4dlbABIjJxnwPS3x13R/Nbfmlugkz7XpX20DmZ0IhPuGBR95sOpDATIjfW51fuStCVVni4='>
    <input  name='autoRedirect' value='0'>
    <input  name='paymentMethod' value='CC_PAYMENT_METHOD'>
    <input  name='emailAddr' value='johndoe@live.com'>
    <input  name='mobileNum' value='0123455500'>
    <button type="submit" class="btn btn-success" >Submit</button>
    <input type='submit' value='asdasd' class="btn">
</form>
Haroon Aslam
  • 1,593
  • 4
  • 11
  • 20

3 Answers3

35

You can do it in following way:

<form #form action='https://easypaystg.easypaisa.com.pk/easypay/Index.jsf' method='post'>
    ...
    <button type="submit" class="btn btn-success" (click)="form.submit()">Submit</button>
    ...
</form>
Anshuman Jaiswal
  • 5,352
  • 1
  • 29
  • 46
7

Use the ngNoForm attribute as documented. This will prevent all "magic" Angular behavior, and you will be able to submit the form in the native way (with page reload).

So something similar to:

<form ngNoForm action='https://easypaystg.easypaisa.com.pk/easypay/Index.jsf' method='post'>
    <input  name='storeId' value='4950'>
    ...
    <input type='submit' value='asdasd' class="btn">
</form>
PowerKiKi
  • 4,539
  • 4
  • 39
  • 47
4

Posting a form directly causes a page reload, that's usually not what you want in an Angular application (SPA). Grab the data from the form and send an HTTP request from your code to the server instead.

You should leverage the NgSubmit directive, as described here

Javier Aviles
  • 7,952
  • 2
  • 22
  • 28