Как исправить «Выражение изменилось после того, как оно было проверено»? - PullRequest
0 голосов
/ 07 мая 2018

Это код Anglar ExpressionChangedAfterItHasBeenCheckedError: Выражение изменилось после его проверки. Предыдущее значение: 'ngIf: undefined'. Текущее значение: 'ngIf: false'.

 oldEmail: String;
 shouldBeUnique(): Boolean {
     if (this.oldEmail == this.email.value) {
         return false;
     }
     this.oldEmail = this.email.value;
     let param: String;
     param = this.email.value;
     this.http
     .get(this.url + "IsUniqueEmail" + "/" + param)
     .subscribe(response => {
       console.log(response.json());
       if (response.status == 200) return true;
       return false;
     });
 }

Это HTML-код.

<div class="input-fild">
    <mat-form-field class="example-full-width">
      <input matInput placeholder="Email" required formControlName="email" id="email" type="email">
      <mat-error *ngIf="email.touched && email.invalid">
        <mat-error *ngIf="email.errors.required">Email is required</mat-error>
        <mat-error *ngIf="email.errors.email && !email.errors.required && !(email.errors.cannotContainSpace)">Email is'nt valid</mat-error>
        <mat-error *ngIf="email.errors.cannotContainSpace">Email cannot contain space</mat-error>
      </mat-error>
      <mat-error *ngIf="email.valid && email._pendingTouched">
        <mat-error *ngIf="shouldBeUnique()">Email is shouldBeUnique</mat-error>
      </mat-error>
    </mat-form-field>
    <button (click)="show()" mat-raised-button color="primary">Show</button>
  </div>

`

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...