Created
March 7, 2023 06:45
-
-
Save av1v3k/ed9dfaaff5e0f2b9f09e387a464c5ff2 to your computer and use it in GitHub Desktop.
Validating with Service call on typing text - Angular
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
searchSubject = new Subject(); | |
searchResult$: Observable<any>; | |
this.searchResult$ = this.searchSubject.pipe( | |
debounceTime(1000), | |
distinctUntilChanged(), | |
switchMap((searchText: string) => { | |
return this.service.validateZipCode(searchText) | |
}), | |
map((res: any) => { | |
return { ...res } | |
}) | |
); | |
this.searchResult$.subscribe( | |
data => { | |
console.warn('subscribe', data); | |
if (data.hasOwnProperty('errorMessage')) { | |
this.setAddressFormErrored(data.errorMessage); | |
} else { | |
this.setAddressFormErrored(''); | |
this.userData.city = data.city; | |
this.userData.state = data.state; | |
this.validateStateAfterResponse(data.state); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment