question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Subscribing in template using async pipe

See original GitHub issue

I define the Observable as

this.cart$ = this.storage.observe('cart');

and then in the template I just subscribe {{(cart$ | async | json)}} but I get null.

Note: If I try to fetch the value using a decorator @LocalStorage('cart') cart: Cart; I see that the property cart does contain what I expect…

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
PillowPillowcommented, Nov 6, 2020

Hello @mackelito , Yes this project’s still alive since we’re using it in production in my company’ projects. What you are facing of is the expected behavior. The observe() method act as cold observable. If you don’t wanna use the decorators to bind your property you have to use the startWith operator to setup the start value.

this.storage.observe('cart').pipe(
    startWith(this.storage.retrieve('cart'))
).subscribe(e => console.log('e', e));
0reactions
mackelitocommented, Nov 9, 2020

Glad to hear it’s still alive 👍

I had totally forgotten about the concept of hot/cold observables… 😄 thx for the reminder!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Managing Subscriptions in Angular With the Async Pipe
Easily subscribe, unwrap data and unsubscribe from observables in Angular 2+ with the use of the async pipe in your templates.
Read more >
subscribe() vs | async Pipe | by Tomas Trajan | Angular In ...
Using the subscribe() method and storing the state on the component instance, todos$. · The | async pipe unwraps the state object directly...
Read more >
Angular: Use Observable Subscriptions & Async-Pipe to ...
Async -Pipe is an Angular built in tool to manage Observable-Subscriptions. We can easily simplify functionality of an Angular code using the async...
Read more >
When to use the subscribe method or async pipe in Angular?
This post explains when to use subscribe method or async pipe in working with observable data in an Angular application.
Read more >
Angular Reactive Templates with ngIf and the Async Pipe
As we can see, we have subscribed to the observable returned by the service layer and defined a local variable that contains the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found