I have an array of strings that i get as a value from an observable.
In the view I am trying to display the values with async pipe.
the template displays only the value of the last item and multiplies it in the number of recieved objects.
When I log the values to the console inside the subscribe method the results are displayed as they should be.
component.ts
hideCategories = true;
categories$:Observable<string[]> = this.categoriesQuery.selectAll();
destroy$: Subject<boolean> = new Subject<boolean>();
ngOnInit()
{
this.categoriesQuery.selectedIsCategoriesLoaded$.pipe(
filter(isLoaded => !isLoaded),
switchMap((isLoaded) =>
{
return this.ticketService.fetchCategories()
}),
takeUntil(this.destroy$))
.subscribe(console.log);
}
component.html
<ul *ngIf="!hideCategories && categories$ | async as categories" class="search-ul w-100" id="categories">
<li *ngFor="let cat of categories" (click)="onSelectCategory(cat)" class="pointer" tabindex="0">{{cat}}</li>
</ul>
Not sure if it's related but I am using datorama akita for state managment.
----Edit----
this.categoriesQuery.selectAll()
Is derived from datorama akita QueryEntity Class.
service.ts
fetchCategories()
{
return this.http.get<string[]>(environment.endpoints.tickets.getCategories).pipe(
tap(categories =>
this.categoriesStore.setCategories(categories, true)
));
}
store.ts
@StoreConfig({ name: 'categories' })
export class CategoriesStore extends EntityStore<CategoriesState>{
constructor()
{
super(createInitialState());
}
setCategories(categories: string[], isCategoriesLoaded: boolean)
{
this.set(categories);
this.update(state =>
({
...state,
isCategoriesLoaded
}))
}
}
export function createInitialState(): CategoriesState
{
return {
isCategoriesLoaded: false
}
}