【发布时间】:2020-09-16 06:55:55
【问题描述】:
我的子组件中有如下订阅。
ngOnInit{
this.subscription = this._cs.recieveData.subscribe((res) => {
this.data= res;
});
UseDatafromSubs(this.data){
//do Something
}
}
我在上面的子组件中有另一个方法(UseDatafromSubs),它接受我的订阅响应作为参数:
在我的 ParentComponent 中,我正在更新如下服务:
senddata(){
this._cs.send(sendData);
}
我能够从父级向子级发送和接收更新的数据,但是当新的订阅数据到来时,我的 useDataFromSubs 没有被调用,为了使用数据,它没有将订阅响应视为范围。我尝试使用如下添加方法:
this.subscription = this._cs.recieveData.subscribe((res) => {
this.data= res;
}).add(()=>this.UseDatafromSubs(this.data));
但没用。
有人可以帮忙吗。
提前致谢。
【问题讨论】:
-
听起来像是错误的模式。不要传递订阅,传递 observables。
标签: angular typescript rxjs subscription