Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.share() with .subscribe() _isScalar is missing

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!");
      })
like image 618
eulercode Avatar asked Sep 14 '17 06:09

eulercode


Video Answer


1 Answers

.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;
  }) 
like image 101
Günter Zöchbauer Avatar answered Oct 02 '22 08:10

Günter Zöchbauer