Question:
Angular 8.2 Type 'Subscription' is missing the following properties from type

Solution

There might be several issues while you are coding in Angular 8.2. You can opt for several possibilities as shown below:


In order to return an rxjs Subscription, you need to change subscribe method:

import { Subscription } from 'rxjs';

...

subscribe(generator: Function): Subscription {

  return this.subscriber.subscribe(generator);

}


You just need to rely on the caller to subscribe. Plus, refactor your subscribe method to just return the observable:


import { Observable } from 'rxjs';

...

getObservable(): Observable {

  return this.subscriber;

}

...

// in calling code:

broadcastService.getObservable().subscribe(value => {

  // ...

});


As an Angular >EventEmitter, or essentially a wrapper around a rxjs >Subject, the variable you named subscriber functions as a data channel into which you can send data using the emit method and receive data using the subscribe method. When using the unsubscribe method to end a subscription, the subscribe method returns a Subscription.


Suggested blogs:

>How can I access specific data inside a JSON file on an Angular?

>HTTP request after another but only care about first one in Angular?

>Why am I getting unexpected parent reaction to child button Angular?

>How can I combine multiple HTTP calls in Angular using RxJS?

>Why Ng serve doesn't work in Angulars?

>How to use JSON:API along with Angular/RxJs?

>Why Ng server doesn't work in Angulars?

>How to operate data before return it using Angular16?


Ritu Singh

Ritu Singh

Submit
0 Answers