I know that the question has already asked on Stackoverflow but the proposed solutions doesn't work.
I need to loop into a list containing categories and items. I want to display only one time the category so I need to test if the category is same that the previous one. If it's the same I don't display it but if not I display the new category. Therefore I want to declare a variable to store the current category name.
Is it possible? If not how can I do to test previous category and new one?
Thanks
Edit : My method to get datas :
getMenuByTruck = () =>{
const id: string = this.activeRoute.snapshot.params['id'];
const apiMenu: string = environment.apiAddress + 'TruckMenu/' + id;
this.repository.getData(apiMenu)
.pipe(finalize(() => {
this.updateTruckName();
}))
.subscribe(response => {
this.menu = response as Menu[];
},
(error) =>{
this.errorHandler.handleError(error);
this.errorMessage = this.errorHandler.errorMessage;
})
}
and my loop into html code :
<div class="title" *ngFor="let m of menu">
<h3>{{m.foodCategory?.description}}</h3>
</div>