Angular 2 Ionic Form

前提是你 提交于 2020-01-16 16:14:12

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!