I am having trouble with .subscribe()
in angular, where the values I use to update the UI are not themselves updating. In my Inspect Element Network tab, I can see that the data is correct. And before anyone mentions it, the nested .subscribe()
is not the problem, the first subscribe is always true, as the user must be logged in to view this screen.
ngOnInit(): void {
this.service.isLoggedIn().subscribe( u => {
this.user = u;
this.id = this.location.selected.value.id
this.location.getSelected().subscribe( selectedLocation => {
if (selectedLocation) {
this.showTable = true;
if (selectedLocation.members) {
this.member = true;
}
if (selectedLocation.schedules) {
this.schedules = true;
}
if (selectedLocation.team) {
this.team = true;
}
}
});
});
getSelected(): Observable<Location> {
if (this.selected && this.selected.value) {
return of(this.selected.value);
} else {
return this.selected.asObservable();
}
}
This is what is shown in my Network tab in Inspect Element:
{
"id": 4,
"member": true,
"schedules": true,
"team": false
}
However, when I go to this page, for example, the if(selectedLocation)
is triggered, but the other if()
s are not, and thus my variables are not changed, therefore neither is the UI.