this.pickupStatus.emit is not a function











up vote
3
down vote

favorite












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?










share|improve this question






















  • @PankajParkar .next also gives the same error
    – Patrick Obafemi
    Nov 10 at 18:00










  • Replace this.pickupStatus.emit(value); by this. pickupRequest.next(value);
    – Sunil Singh
    Nov 10 at 18:13












  • @PatrickObafemi my bad. check my answer with detailed explanation.
    – Pankaj Parkar
    Nov 10 at 18:17















up vote
3
down vote

favorite












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?










share|improve this question






















  • @PankajParkar .next also gives the same error
    – Patrick Obafemi
    Nov 10 at 18:00










  • Replace this.pickupStatus.emit(value); by this. pickupRequest.next(value);
    – Sunil Singh
    Nov 10 at 18:13












  • @PatrickObafemi my bad. check my answer with detailed explanation.
    – Pankaj Parkar
    Nov 10 at 18:17













up vote
3
down vote

favorite









up vote
3
down vote

favorite











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?










share|improve this question













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?







angular typescript ionic3






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 10 at 17:52









Patrick Obafemi

112113




112113












  • @PankajParkar .next also gives the same error
    – Patrick Obafemi
    Nov 10 at 18:00










  • Replace this.pickupStatus.emit(value); by this. pickupRequest.next(value);
    – Sunil Singh
    Nov 10 at 18:13












  • @PatrickObafemi my bad. check my answer with detailed explanation.
    – Pankaj Parkar
    Nov 10 at 18:17


















  • @PankajParkar .next also gives the same error
    – Patrick Obafemi
    Nov 10 at 18:00










  • Replace this.pickupStatus.emit(value); by this. pickupRequest.next(value);
    – Sunil Singh
    Nov 10 at 18:13












  • @PatrickObafemi my bad. check my answer with detailed explanation.
    – Pankaj Parkar
    Nov 10 at 18:17
















@PankajParkar .next also gives the same error
– Patrick Obafemi
Nov 10 at 18:00




@PankajParkar .next also gives the same error
– Patrick Obafemi
Nov 10 at 18:00












Replace this.pickupStatus.emit(value); by this. pickupRequest.next(value);
– Sunil Singh
Nov 10 at 18:13






Replace this.pickupStatus.emit(value); by this. pickupRequest.next(value);
– Sunil Singh
Nov 10 at 18:13














@PatrickObafemi my bad. check my answer with detailed explanation.
– Pankaj Parkar
Nov 10 at 18:17




@PatrickObafemi my bad. check my answer with detailed explanation.
– Pankaj Parkar
Nov 10 at 18:17












3 Answers
3






active

oldest

votes

















up vote
1
down vote



accepted










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.






share|improve this answer






























    up vote
    1
    down vote













    .emit() only works on EventEmitter, using .next() on pickup status won't work as Observable is read-only.






    share|improve this answer





















    • hello. next() also gives the same error.
      – Patrick Obafemi
      Nov 10 at 17:59










    • .next() only works on Subject or any class that extends Subject. Convert pickupStatus to eventEmitter and use emit() and it will work.
      – Andrei Dumitrescu-Tudor
      Nov 10 at 18:02










    • @AndreiDumitrescu-Tudor .next will work for both Subject and Behavior subject. Every observable in RxJs .next is the default method to emit the value
      – NinjaJami
      Nov 10 at 18:26










    • @NinjaJami as per reactivex.io/rxjs/class/es6/Observable.js~Observable.html observable is read only. Subject is the one that can emit values via next().
      – Andrei Dumitrescu-Tudor
      Nov 10 at 18:36










    • @AndreiDumitrescu-Tudor here is an example stackblitz.com/edit/…
      – NinjaJami
      Nov 10 at 18:38


















    up vote
    1
    down vote













    emit method exist on EventEmitter object not on BehaviourSubject. Over here you are exposing the stream using this.pickupRequest.asObservable() method. I believe this is safest way to expose a stream so that the consumer of this stream will not push any data into a stream. Basically to prevent leaky abstraction. If consumer tries to do pickupStatus.next(data) on that it will result to an error. This is expected behavior. This way we give readonly access to consumer of a stream.



    In order to send data over a stream you have to call .next method on BehaviorSubject instance, it auto magically let subscribers knows that new data has pushed into a stream.



    pickupRequest.next(data)





    share|improve this answer























      Your Answer






      StackExchange.ifUsing("editor", function () {
      StackExchange.using("externalEditor", function () {
      StackExchange.using("snippets", function () {
      StackExchange.snippets.init();
      });
      });
      }, "code-snippets");

      StackExchange.ready(function() {
      var channelOptions = {
      tags: "".split(" "),
      id: "1"
      };
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function() {
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled) {
      StackExchange.using("snippets", function() {
      createEditor();
      });
      }
      else {
      createEditor();
      }
      });

      function createEditor() {
      StackExchange.prepareEditor({
      heartbeatType: 'answer',
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader: {
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      },
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      });


      }
      });














       

      draft saved


      draft discarded


















      StackExchange.ready(
      function () {
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53241807%2fthis-pickupstatus-emit-is-not-a-function%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      3 Answers
      3






      active

      oldest

      votes








      3 Answers
      3






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes








      up vote
      1
      down vote



      accepted










      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.






      share|improve this answer



























        up vote
        1
        down vote



        accepted










        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.






        share|improve this answer

























          up vote
          1
          down vote



          accepted







          up vote
          1
          down vote



          accepted






          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.






          share|improve this answer














          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.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 10 at 18:13

























          answered Nov 10 at 18:07









          SiddAjmera

          9,40921037




          9,40921037
























              up vote
              1
              down vote













              .emit() only works on EventEmitter, using .next() on pickup status won't work as Observable is read-only.






              share|improve this answer





















              • hello. next() also gives the same error.
                – Patrick Obafemi
                Nov 10 at 17:59










              • .next() only works on Subject or any class that extends Subject. Convert pickupStatus to eventEmitter and use emit() and it will work.
                – Andrei Dumitrescu-Tudor
                Nov 10 at 18:02










              • @AndreiDumitrescu-Tudor .next will work for both Subject and Behavior subject. Every observable in RxJs .next is the default method to emit the value
                – NinjaJami
                Nov 10 at 18:26










              • @NinjaJami as per reactivex.io/rxjs/class/es6/Observable.js~Observable.html observable is read only. Subject is the one that can emit values via next().
                – Andrei Dumitrescu-Tudor
                Nov 10 at 18:36










              • @AndreiDumitrescu-Tudor here is an example stackblitz.com/edit/…
                – NinjaJami
                Nov 10 at 18:38















              up vote
              1
              down vote













              .emit() only works on EventEmitter, using .next() on pickup status won't work as Observable is read-only.






              share|improve this answer





















              • hello. next() also gives the same error.
                – Patrick Obafemi
                Nov 10 at 17:59










              • .next() only works on Subject or any class that extends Subject. Convert pickupStatus to eventEmitter and use emit() and it will work.
                – Andrei Dumitrescu-Tudor
                Nov 10 at 18:02










              • @AndreiDumitrescu-Tudor .next will work for both Subject and Behavior subject. Every observable in RxJs .next is the default method to emit the value
                – NinjaJami
                Nov 10 at 18:26










              • @NinjaJami as per reactivex.io/rxjs/class/es6/Observable.js~Observable.html observable is read only. Subject is the one that can emit values via next().
                – Andrei Dumitrescu-Tudor
                Nov 10 at 18:36










              • @AndreiDumitrescu-Tudor here is an example stackblitz.com/edit/…
                – NinjaJami
                Nov 10 at 18:38













              up vote
              1
              down vote










              up vote
              1
              down vote









              .emit() only works on EventEmitter, using .next() on pickup status won't work as Observable is read-only.






              share|improve this answer












              .emit() only works on EventEmitter, using .next() on pickup status won't work as Observable is read-only.







              share|improve this answer












              share|improve this answer



              share|improve this answer










              answered Nov 10 at 17:58









              Andrei Dumitrescu-Tudor

              875




              875












              • hello. next() also gives the same error.
                – Patrick Obafemi
                Nov 10 at 17:59










              • .next() only works on Subject or any class that extends Subject. Convert pickupStatus to eventEmitter and use emit() and it will work.
                – Andrei Dumitrescu-Tudor
                Nov 10 at 18:02










              • @AndreiDumitrescu-Tudor .next will work for both Subject and Behavior subject. Every observable in RxJs .next is the default method to emit the value
                – NinjaJami
                Nov 10 at 18:26










              • @NinjaJami as per reactivex.io/rxjs/class/es6/Observable.js~Observable.html observable is read only. Subject is the one that can emit values via next().
                – Andrei Dumitrescu-Tudor
                Nov 10 at 18:36










              • @AndreiDumitrescu-Tudor here is an example stackblitz.com/edit/…
                – NinjaJami
                Nov 10 at 18:38


















              • hello. next() also gives the same error.
                – Patrick Obafemi
                Nov 10 at 17:59










              • .next() only works on Subject or any class that extends Subject. Convert pickupStatus to eventEmitter and use emit() and it will work.
                – Andrei Dumitrescu-Tudor
                Nov 10 at 18:02










              • @AndreiDumitrescu-Tudor .next will work for both Subject and Behavior subject. Every observable in RxJs .next is the default method to emit the value
                – NinjaJami
                Nov 10 at 18:26










              • @NinjaJami as per reactivex.io/rxjs/class/es6/Observable.js~Observable.html observable is read only. Subject is the one that can emit values via next().
                – Andrei Dumitrescu-Tudor
                Nov 10 at 18:36










              • @AndreiDumitrescu-Tudor here is an example stackblitz.com/edit/…
                – NinjaJami
                Nov 10 at 18:38
















              hello. next() also gives the same error.
              – Patrick Obafemi
              Nov 10 at 17:59




              hello. next() also gives the same error.
              – Patrick Obafemi
              Nov 10 at 17:59












              .next() only works on Subject or any class that extends Subject. Convert pickupStatus to eventEmitter and use emit() and it will work.
              – Andrei Dumitrescu-Tudor
              Nov 10 at 18:02




              .next() only works on Subject or any class that extends Subject. Convert pickupStatus to eventEmitter and use emit() and it will work.
              – Andrei Dumitrescu-Tudor
              Nov 10 at 18:02












              @AndreiDumitrescu-Tudor .next will work for both Subject and Behavior subject. Every observable in RxJs .next is the default method to emit the value
              – NinjaJami
              Nov 10 at 18:26




              @AndreiDumitrescu-Tudor .next will work for both Subject and Behavior subject. Every observable in RxJs .next is the default method to emit the value
              – NinjaJami
              Nov 10 at 18:26












              @NinjaJami as per reactivex.io/rxjs/class/es6/Observable.js~Observable.html observable is read only. Subject is the one that can emit values via next().
              – Andrei Dumitrescu-Tudor
              Nov 10 at 18:36




              @NinjaJami as per reactivex.io/rxjs/class/es6/Observable.js~Observable.html observable is read only. Subject is the one that can emit values via next().
              – Andrei Dumitrescu-Tudor
              Nov 10 at 18:36












              @AndreiDumitrescu-Tudor here is an example stackblitz.com/edit/…
              – NinjaJami
              Nov 10 at 18:38




              @AndreiDumitrescu-Tudor here is an example stackblitz.com/edit/…
              – NinjaJami
              Nov 10 at 18:38










              up vote
              1
              down vote













              emit method exist on EventEmitter object not on BehaviourSubject. Over here you are exposing the stream using this.pickupRequest.asObservable() method. I believe this is safest way to expose a stream so that the consumer of this stream will not push any data into a stream. Basically to prevent leaky abstraction. If consumer tries to do pickupStatus.next(data) on that it will result to an error. This is expected behavior. This way we give readonly access to consumer of a stream.



              In order to send data over a stream you have to call .next method on BehaviorSubject instance, it auto magically let subscribers knows that new data has pushed into a stream.



              pickupRequest.next(data)





              share|improve this answer



























                up vote
                1
                down vote













                emit method exist on EventEmitter object not on BehaviourSubject. Over here you are exposing the stream using this.pickupRequest.asObservable() method. I believe this is safest way to expose a stream so that the consumer of this stream will not push any data into a stream. Basically to prevent leaky abstraction. If consumer tries to do pickupStatus.next(data) on that it will result to an error. This is expected behavior. This way we give readonly access to consumer of a stream.



                In order to send data over a stream you have to call .next method on BehaviorSubject instance, it auto magically let subscribers knows that new data has pushed into a stream.



                pickupRequest.next(data)





                share|improve this answer

























                  up vote
                  1
                  down vote










                  up vote
                  1
                  down vote









                  emit method exist on EventEmitter object not on BehaviourSubject. Over here you are exposing the stream using this.pickupRequest.asObservable() method. I believe this is safest way to expose a stream so that the consumer of this stream will not push any data into a stream. Basically to prevent leaky abstraction. If consumer tries to do pickupStatus.next(data) on that it will result to an error. This is expected behavior. This way we give readonly access to consumer of a stream.



                  In order to send data over a stream you have to call .next method on BehaviorSubject instance, it auto magically let subscribers knows that new data has pushed into a stream.



                  pickupRequest.next(data)





                  share|improve this answer














                  emit method exist on EventEmitter object not on BehaviourSubject. Over here you are exposing the stream using this.pickupRequest.asObservable() method. I believe this is safest way to expose a stream so that the consumer of this stream will not push any data into a stream. Basically to prevent leaky abstraction. If consumer tries to do pickupStatus.next(data) on that it will result to an error. This is expected behavior. This way we give readonly access to consumer of a stream.



                  In order to send data over a stream you have to call .next method on BehaviorSubject instance, it auto magically let subscribers knows that new data has pushed into a stream.



                  pickupRequest.next(data)






                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Nov 10 at 18:30

























                  answered Nov 10 at 18:14









                  Pankaj Parkar

                  111k15157232




                  111k15157232






























                       

                      draft saved


                      draft discarded



















































                       


                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function () {
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53241807%2fthis-pickupstatus-emit-is-not-a-function%23new-answer', 'question_page');
                      }
                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      Florida Star v. B. J. F.

                      Danny Elfman

                      Lugert, Oklahoma