I'm subscribing to a store property in a component constructor
constructor(private someService: SomeService){
someService.someObservable.subscribe((data: Some)=> {
this.some = data;
console.log('changed');
});
}
In the service, the constructor looks like this:
constructor(private store: Store<any>){
this.someObservable = <Observable<{}>>store.select('some');
}
I keep changing the state of this object, but the logging only appear once.
What's also weird is that I'm accessing the this.some
property directly in my template (without async
pipe), and it updates perfectly!
It seems like the this.some
property is being updated, but the next()
in the subscription isn't working.
help anyone? thanks!
Just like calling a function multiple times gives you multiple return values. So if you subscribe multiple times to an an Observable returned by the Angular HTTP Client, that will result in multiple HTTP requests!
Subscribing to an Observable is like calling a function, providing callbacks where the data will be delivered to. This is drastically different to event handler APIs like addEventListener / removeEventListener . With observable.subscribe , the given Observer is not registered as a listener in the Observable.
Subscribe() is a method in Angular that connects the observer to observable events. Whenever any change is made in these observable, a code is executed and observes the results or changes using the subscribe method. Subscribe() is a method from the rxjs library, used internally by Angular.02-Jan-2022.
Observables in Angular are generally declarative i.e., if you ought to define a function for value publication. It won't be executed until and unless it is subscribed. The subscriber is termed as a consumer who receives the notifications until the function completes itself or until they manually unsubscribe.
In my very similar case the problem was that one of the subscription handlers was throwing an error. When an error is encountered the observable stream stops emitting new values.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With