这是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>
`