问题
I'm trying to submit a form in angular using ionic
<form method="post" class="form-horizontal" action="https://localhost:44370/Account/ExternalLogin">
<div>
<p>
<!-- ion-button block [disabled]="isDisabled" -->
<button
name="provider" value="Coinbase" type="submit"
title="Log in using your Coinbase account">
Coinbase
</button>
</p>
</div>
</form>
However, when I click the submit button nothing occurs.
回答1:
Use the ngForm (template or reactive way) provided by angular. Also for you button create it twice, one with invalid and other with valid form state.
use (ngSubmit)="onSubmit()"
<form #form method="post" (ngSubmit)="onSubmit()" class="form-horizontal" action="https://localhost:44370/Account/ExternalLogin">
<div>
<p>
<button ion-button block [disabled]="isDisabled" type="submit" title="Log in using your Coinbase account">
Coinbase
</button>
<input type="hidden" name="provider" value="Coinbase">
</p>
</div>
</form>
P.D.: It's wise to always valite the data you want to submit programatically to avoid XSS attacks.
来源:https://stackoverflow.com/questions/54338220/angular-2-ionic-form