
1 minute read
Promise inAngular Development
The computer language JavaScript was developed to provide interactivity to web pages. The callback functions in JavaScript coding, however, provide a significant challenge for developers. The reason is that when visitors interact with a web page, they must cope with asynchronous events.
Many developers found these callback routines to be a hassle, especially when using JavaScript to create intricate and rich programmes for contemporary browsers. To overcome such complexity, ES6 introduced Promises, a modern and powerful abstraction for writing asynchronous code in a better and easily maintainable way.
Advertisement
This presentation will explain what a promise is in an Angular application and introduce you to the idea of JavaScript promises, which were first introduced in ES6.
What is Promise in JavaScript?
A promise is a JavaScript or TypeScript object that may produce a value at some point in time. A promise may be in one of 4 possible states:
● fulfilled –The action relating to the promise succeeded
● rejected – The action relating to the promise failed just because an error occurs during promise implementation
● pending – It’s an initial state that hasn’t fulfilled or rejected yet
● settled – Has fulfilled or rejected