I have a form which loads user information from a BehaviorSubject. If I edit any input on this form and navigate away from the page WITHOUT hitting submit, the user information is updated in the subject regardless.
I do not have a grasp of why the Subject is being updated when I have not called next() on the BehaviorSubject.
===SUBJECT CLASS===
userDataReceiver$: Observable<UserModel>;
private userDataObserver = new BehaviorSubject(null);
constructor() {
this.userDataReceiver$ = this.userDataObserver.asObservable();
}
sendUserDataToSubscriber(data: UserModel) {
this.userDataObserver.next(data);
}
===USER CLASS===
userDataReceiver: Subscription;
ngOnInit() {
this.userDataReceiver = this.observerService.userDataReceiver$
.subscribe(res => this.user = res);
}
ngOnDestroy() {
this.userDataReceiver.unsubscribe();
}
this.user is being used in the form on the html page to load/save user data. If an input is edited in the html page without saving the form, navigating away from the page will still cause the user object to be updated. Navigating back to the html page will display the updated user input.