What is the difference between promise and observable ?
What is the difference between promise and observable ?
In Angular, both Promises and Observables are used to handle asynchronous operations, but they have distinct characteristics and use cases.
A Promise in Angular is a JavaScript object that represents the eventual completion or failure of an asynchronous operation and its resulting value. Here are some key features of Promises:
.then()
for resolving and .catch()
for rejecting, which are used to handle errors and successful responses[1][2].Observables, provided by the RxJS library in Angular, offer a more powerful and flexible approach to handling asynchronous and event-based programs. They have the following characteristics:
unsubscribe()
method, which stops the listener from receiving further values. This is particularly useful for long-lived or resource-intensive operations...middle
Gợi ý câu hỏi phỏng vấn
Chưa có bình luận nào