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();
}
);
this.pageService.getSub().subscribe()
? Provide some context. – fridoconsole.log
in the constructor to check if it's executed twice. – frido