Wait for all API request call on input method in textbox, Angular

  angular, typescript

I am calling an API to validate number exist or not in our database. I am calling the method on (input) event of textbox which will call the API. Now If I type in input box ‘1234’ then there will be four API calls made, first for ‘1’, second for ’12’, third for ‘123’, fourth for ‘1234’. Now if ‘123’ does not exist in database API will return ‘true’ and button will be enabled, If ‘1234’ exist in database, API will return ‘false’ and button will be disabled. The issue is for some split seconds the button will be enabled as ‘123’ was true and in the textbox it is ‘1234’ as API call for the fourth request is still pending. So button will be enabled for ‘1234’ and this value in textbox will be used in further process which we don’t want. Any better way how to handle this type of case?

Source: Angular Questions

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.