I am trying to use share()
with subscribe()
but got error message as follow. Initially, i started with subscribe. How can this be fix?
My intention is to execute the logic in subscribe. Share is needed to prevent multiple call with async pipe.
Type 'Subscription' is not assignable to type 'Observable'.
Property '_isScalar' is missing in type 'Subscription'. (property) PostDetailPage.post: Observable
this.post = this.data.getPostById(this.postId).share().subscribe(data => {
this.post = data;
},
err => {
console.log("Oops!");
})
.subscribe()
returns a Subscription
(allows to unsubscribe).
If you want an Observable
, don't use subscribe(...)
.
You can instead use map(...)
this.post = this.data.getPostById(this.postId).share().map(data => {
this.post = data;
})
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