M
M
MrRob0t2018-05-06 14:46:05
Angular
MrRob0t, 2018-05-06 14:46:05

What properties should be in ng-if so that the method is not called all the time?

I am using reactive forms in Angular and Angular Material.
I have a mail uniqueness check in the shouldBeUnique() method in which I call the server.
What properties should be in ng-if so that this method is not called all the time.

<mat-error *ngIf="email.valid && email.touched">
            <mat-error *ngIf="shouldBeUnique()">Email is shouldBeUnique</mat-error>
          </mat-error>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
C
Coder321, 2018-05-07
@MrRob0t

Make a variable

_shouldBeUnique = false;
shouldBeUnique(){
request()
.subscribe(res=>(this._shouldBeUnique  = res))
}

and enter the _shouldBeUnique variable into the template

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question