Observers are the perfect companion for services.
That's because Angra promotes the reactive programming.
Right now, my template is getting the countdown property of my term of service.
That's not reactive.
Angourie is checking this value every time a best approach would be the service to tell when this value
has changed.
If the service signals a company that this kind of value has changed, then I clearly need observables.
However, in this case, I don't want to model Bounden as a simple fluke's of ephemeral data that's
come to an end.
Candombe must always have a value and that's the reason why we need behaviour's subjects.
OK then from time is that yes, we can remove the current countdown.
I remove this and then I can create the behavior subject to generate the count on that rerate countdown
sors equals new behavior subject of type.
No, I am going to set the value to zero this behavior subject.
I have to import it.
From Eric, SJS behavior subject and always remember, because I have a lot of problems, it is that
this behavior with oh not you.
Oh, so remember, you have to spell it like American English, OK, as before, I don't want to expose
this subject to the company, but all of the absorbable.
So I make a public reference public countdown dollar because it's going to be an observable equals.
There's that countdown source that as absorbable I'm going to reorder read that little bit.
So it looks at your subjects with subjects, observables with observables.
And let's see what are the differences in behavior.
Subject is like a subject, but with a difference with the state.
BEHEADERS subjects always have a value.
That's what I have to set an innate value.
When you subscribe to a behavior subject, you get the last available value, tossing them value.
You also use the next method so I can go to discount on here.
This not longer exist, but I can read this.
That cannot source that next.
And I think here any ability to discount that right now to zero with there's that in it.
Another interesting thing about various subjects is that you can always get the current value.
And that's what I am going to do here in the countdown here instead of this and one of the days that
countdown source.
That the next and then three years, the current value, there's that countdown, SUVs that get value.
So I got the grumbly and I substract one because that's what I wanted to do.
And I'll do the same in prison scandal counselors that get value if the value is less frequent than
zero.
I send the signal finished.
Otherwise I continue with the countdown.
So my absorbable countdown is ready and now I have to use it in the component.
I could do the same as before.
In time I comandantes like subscribing to the observer, saying the values and your property on the
company and it will be read from the template.
But I'm going to do something way better than this.
All this work will be done by a pipe.
Angler provides the async pipe that subscribes to unobservable and returns the last animated value.
But also when the company gets destroyed, the sink pipe cancels the subscription for you.
So it removes all the boilerplate we have written before as long as you use it on the template, OK.
So to access the observer flow from template I was using here, time I come down to Mekonnen does not
exist now, but they have time.
I condola and then they use the pipe.
What I have to do is just my absorbable the pipe saying and the name of my pipe.
In this case I think this way I'm easily subscribing to my absorbable and my subscription is cancelled
for free.
One the component is destroyed.
Please note that the syntax highlighter is also complaining here because I'm using this time to count
on in the progress bar.
So what I can do here is just use an expression between parentheses so I can subscribe to my absorbable
with the async pipe.
This way I get them.
They did value that I can substract to init and it works fine if I see the results.
If I click play my countdown and my problem worked as expected.
The difference now, however, is that now my countdown is received through unobservable in a completely
reactive way.
So I'm writing a more efficient code.