Angular 2 – Async Validator – Username/email availability check

In this post I will show you, how we can create custom async validator to check for email availability, same logic you can apply for username or other async validations.

Lets create a component:

Here is my user service:

Backed server response for unregistered email will be null and for registered email address will be as shown below –

I hope you like this Post, Please feel free to comment below, your suggestion and problems if you face - we are here to solve your problems.

0 0 vote
Article Rating
Subscribe
Notify of
guest
8 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Mahaveer Choudhary
Mahaveer Choudhary
3 years ago

great tutorial keep it up

Adrian Dobrowolski
Adrian Dobrowolski
3 years ago

I got There is no directive with “exportAs” set to “ngModel”

arjun
3 years ago

Just added the demo files, download it and check.

Lokesh T
Lokesh T
2 years ago

How the formSubmitclicked variable working? in

arjun
2 years ago
Reply to  Lokesh T

we are not using that variable formSubmitclicked , you can remove it.

Frank Martin
Frank Martin
2 years ago

What should API return?? Why http uses post request?

arjun
2 years ago
Reply to  Frank Martin

If Email address already register, server response – {
“statusCode”: 400,
“error”: “Bad Request”,
“message”: “Email address already registerd”
}
If email is new : just return null
Why http uses post request? -because it’s my preferred way.

Alex Clinton
Alex Clinton
2 years ago

how to do using servises with out http? (internal array of users)

DMCA.com Protection Status
8
0
Would love your thoughts, please comment.x
()
x