表单验证无效

时间:2018-01-12 17:35:58

标签: angular forms validation material

我正在使用Angular with Material,当我尝试使用Material的表单验证并在(ngSubmit)中传递表单的值时,该值为空。如果我从输入中删除[formControl],则值将显示在Login函数的console.log消息中。

<form #loginForm="ngForm" (ngSubmit)="Login(loginForm.value)">

<mat-form-field>
  <input matInput type="text" placeholder="Enter Your Username" ngModel name="username" [formControl]="UNFormControl" [errorStateMatcher]="UNMatcher" required>
  <mat-error *ngIf="PCFormControl.hasError('required')">
    Username is <strong>required</strong>
  </mat-error>
</mat-form-field>

<mat-form-field>
  <input matInput type="password" placeholder="Enter Your Password" value="" ngModel name="password" [formControl]="PwdFormControl" [errorStateMatcher]="passwordMatcher" required>
  <mat-error *ngIf="PwdFormControl.hasError('required')">
    Password is <strong>required</strong>
  </mat-error>
</mat-form-field>

<div class="button-container">
  <button mat-raised-button color="primary" type="submit" [disabled]="UNFormControl.hasError('required') || PwdFormControl.hasError('required')">Log In</button>
</div>

<a class="inline-link margin-top-25">Forgot your Password?</a></form>

虽然这里出了什么问题? 感谢

0 个答案:

没有答案