Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

this.pickupStatus.emit is not a function

I have a provider that listens to changes to my firestore database and changes the status of a driver pickup request status. here is my pickuprequest function in my driver's provider

 getDriverPickupRequest(id)
{
this.DriverCollection.doc<Driver>(id).valueChanges()
                .subscribe(data => {
                        this.pickuprequest.changePickupStatus(data.pickupRequest);

} 

Now i have a service that watches the change and emits it to my home page.

private pickupRequest = new BehaviorSubject<boolean>(false);
public pickupStatus = this.pickupRequest.asObservable();

changePickupStatus(value: boolean) {
this.pickupStatus.emit(value);
}

constructor(public http: HttpClient) {
//console.log('Hello PickuprequestProvider Provider');

}

Now i get an error that says 'this.pickupStatus.emit is not a function'. What is wrong with the code?

like image 361
Patrick Obafemi Avatar asked Apr 30 '26 16:04

Patrick Obafemi


1 Answers

A BehaviorSubject has a next method on it that is used to push new values to the observable.

Problem: You're calling emit on pickupStatus which is an Observable when you should have called next on pickupRequest which is a BehaviorSubject

Fix:

private pickupRequest = new BehaviorSubject<boolean>(false);
public pickupStatus = this.pickupRequest.asObservable();

changePickupStatus(value: boolean) {
  this.pickupRequest.next(value);
}

Use this.pickupRequest.next(value); where we are essentially pushing a new value on the pickupRequest which is a BehaviorSubject by using the next method on it.

like image 93
SiddAjmera Avatar answered May 02 '26 09:05

SiddAjmera