Tags: angular
Observables provide support for passing messages between parts of your application. They are use frequently in Angular applications for handling async data flows.
An observable is a stream of data that we can subscribe to. It emits new values over time that we can react to.
For example, an Observable from a HTTP request would emit the response when the request completes. Or a time Observalbe could emit values at regular interval.
Observable help us handle asynchronous data flows in a declarative style. We define the Observable data stream and then subscribe to it to get notified of new values.
Create a new angular app.
ng new angular-observables-demo
cd angular-observables-demo
Add Boostrap
npm install --save bootstrap@latest
and import it in src/styles.css
@import '~bootstrap/dist/css/bootstrap.min.css';
Building a UserService
ng generate service user
And add user.service.ts
It returns an observable of the HTTP response.
Modify app.component.ts
:
For displaying data, you can modify app.component.html
: