[英]How to Subscribe Observable in different Child component in Angular
I have component parent
and two child A
and B
component.我有组件parent
组件和两个子组件A
和B
I created a Observable
in parent
and subscribe in A
by passing though @input
in A
.我在parent
创建了一个Observable
并通过在A
传递@input
来订阅A
。
On change on parent
A
function get calls through subscription.在parent
A
函数上更改时通过订阅获取调用。
But i want to change the B
also.但我也想改变B
i have checked links我检查了链接
I want to get the change of parent
model in all the childrens
我想改变所有childrens
的parent
模型
I have solved :我已经解决了:
let c: Observable<Array<WorkFlow>> = Observable.create((obs: Observer<Array<WorkFlow>>) => {
this._wfService.getWorkFlows(0, 50).subscribe((data: Array<WorkFlow>) => {
this.workFlows = data;
obs.next(this.workFlows);
}, (err: Response) => {
console.error(err);
});
});
this.workFlowsOb = c.shareReplay(1);
I was returning the c
before , now i used c.shareReplay
and share to Observable that is shared to all children components我之前返回c
,现在我使用c.shareReplay
并共享到 Observable 共享给所有子组件
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.