2

I Have a subscription like below in my Child-Component.

ngOnInit{
    this.subscription = this._cs.recieveData.subscribe((res) => {
    this.data= res;
  });
    UseDatafromSubs(this.data){
    //do Something
    }
}

I have another method in child-Component like above (UseDatafromSubs) which accepts my subscription response as parameter:

In my ParentComponent i am updating the service like below:

senddata(){
     this._cs.send(sendData);
}

I am able to send and receive updated Data from Parent to Child, but my useDataFromSubs is not being called when the new subscription data comes,to use the data, its not taking the subscription response as parameter. I tried using add method like below:

 this.subscription = this._cs.recieveData.subscribe((res) => {
    this.data= res;
  }).add(()=>this.UseDatafromSubs(this.data));

but no use.

can somebody please help.

Thanks in Advance.

1
  • Sounds like wrong pattern. Don't pass around subscriptions, pass around observables. Commented May 28, 2020 at 20:10

1 Answer 1

1

Can you just call the method you want inside the subscribe block? e.g.

ngOnInit{
    this.subscription = this._cs.recieveData.subscribe((res) => {
    this.data= res;
    this.UseDatafromSubs(res);
  })
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.