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?
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.
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