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.

Thilak raj
  • 57
  • 7

1 Answers1

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);
  })
}
joshvito
  • 1,498
  • 18
  • 23