In my Angular 13 app, I have this (abbreviated) component.
The event emitted in this.invitedCount.next(successCount); statement is NOT captured by the subscriber.
See the Console log output below.
The Component (abbreviated):
import { BehaviorSubject } from 'rxjs';
@Component({
selector: 'app-signup',
templateUrl: './signup.page.html',
styleUrls: ['./signup.page.scss'],
})
export class SignupPage implements OnInit {
private invitedCount : BehaviorSubject<number> = new BehaviorSubject(0);
currentInvitedCount = this.invitedCount.asObservable();
}
constructor() {
this.currentInvitedCount.subscribe(count => {
console.log('All inviting learners were linked observable. Count: ', count);
if (count == this.invitingPersons.length) {
this.notifyInvitingLearners(true);
}
});
}
myFunction() {
//some code
if (result!=null) {
console.log('successfuly assigned Helper to Learner: ', JSON.stringify(resultAssign));
successCount++;
console.log('Emitting successCount: ', successCount);
this.invitedCount.next(successCount); //Raising event to listener
}
}
Console log:
successfuly assigned Helper to Learner: [{"keyHelper":"H0972000547780993"}]
Emitting successCount: 1
...
...
The log statements in the subscriber (in the constructor) are never logged and not logic is performed there.
Also, there is no unsubscribe at all in the component yet.
What am I missing?