How do observables differ from promises?
Observable | Promise | |
---|---|---|
1. | Used from the library RxJS.import { Observable } from 'rxjs'; |
Built-in API. |
2. | Can show multiple values using setInterval() method |
Can resolve only one async task and cannot be used again |
3. | Can unsubscribe from the observables no longer needed. | A promise cannot be canceled. |
4. | Lazy. Observable is called only when we subscribe. | Not lazy. |
5. | Rich set of operators in the library like map, filter, pipe, retry, etc. | No such additional features available |
BY Best Interview Question ON 01 Mar 2020