I have a Subject in my Angular Service like this:
private sub = new Subject();
sendSub(page: page) {
this.sub.next(page);
}
getSub(): Observable<any> {
return this.sub.asObservable();
}
In my parent component I have subscribed to getSub()
. From my child component I'm sending one next value but in the parent I'm getting two values in subscription.
Need only one value so that my code block executes only once:
subscription: Subscription;
this.subscription = this.pageService
.getSub()
.subscribe(
(data) => {
this.data = data;
this.nextSelection();
}
);
Add Subscribe code in the constructor of the parent component.Here is a fiddle of the same