不能阻止角度反应形式提交

时间:2018-04-19 22:38:34

标签: angular ionic-framework ionic3 angular-reactive-forms

我有一个像这样的被动形式:

<form [formGroup]="loginForm" (ngSubmit)="onLogInFormSubmit($event)">

      <input type="email" formControlName="email" placeholder="Email">

      <input type="password" formControlName="pwd" placeholder="Password">

      <button
        ion-button
        type="submit"
        color="green"
        class="btn btnAuth"
        >LOG IN</button>

    </form>

现在我想按下提交按钮检查我的表格是否有效以及是否不能提交。

我已经在onLogInFormSubmit($event)内向return falsepreventDefault()尝试了这次活动,但这项工作都没有。

难以阻止提交操作或我遗失了什么?

PS。我的表单已在我的.ts文件中正确初始化。

1 个答案:

答案 0 :(得分:0)

最常见的方法是在表单无效时禁用提交按钮:

<button ion-button
    type="submit"
    color="green"
    class="btn btnAuth"
    [disabled]="!nameOfFormObject.valid">LOG IN</button>

查看NgForm对象。

Example.

相关问题