How to implement timeout in Ionic application?

I have an application that makes several ajax calls to pull information from the server and render them on the client. But there was no timeout implemented on the app. I want to set a time out property for the ajax calls and display the users an error message… Can anyone help me implementing that??

Just before calling Ajax call start by running:
"myTo = setTimeout(function(){alert(‘Error message’)},2000)"
then if the Ajax call went fine: “clearTimeout(myTo)”

Can you give an example with an ajax call. This will be very helpful. Thanks in advance.

You can take a look at this post: