I.K*_*nik 5 html html5 typescript angular
这是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;
});
}
Run Code Online (Sandbox Code Playgroud)
这是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>
Run Code Online (Sandbox Code Playgroud)
`