I have an observable variable that gets its value from the store. I have a subscribe method on it to listen to updates. In it I try to assign a regular variable one of the values of the observable variable. I console log it to see if it has been updated and it has but the value is not updated in the template.
I have tried listening to the observable in the template and that works fine. I need however to manipulate the returned answer so I can't do it this way.
I have also tried with
this.cdr.detectChanges();
and that works but it feels hacky and overkill for something so simple. Also just in case someone wonders my component does not have
ChangeDetectionStrategy=OnPush
.
This is how the variable is initialised.
this.filters$ = this.store.let(getListsContactsFilters());
This is what the subscription looks like.
this.filters$.subscribe((filters) => {
this.selectedAreas = filters.selectedAreas;
});
I then do this in the template
<div *ngFor="let area of selectedAreas">
<h1>{{area.title}}</h1>
</div>
I also tried printing out selectedAreas in the template:
{{selectedAreas | json}}
and this stays as an empty array even after the subscribe function is triggered.
Really super simple so god knows why it is not working.
I expect this.selectedAreas to have the value of filters.selectedAreas in the template. Which btw is and array of objects.