I have an array of arrays that I want to use as a directory. The point is to sort all the items according to which letter they begin with.
Here is the code of my item list component :
let itemList = ["Plane","Bird","Boat"];
let directory = [];
for (const item of this.itemList) {
if (this.directory[item.charAt(0).toLowerCase()] == null || undefined) {
this.directory[item.charAt(0).toLowerCase()] = [];
}
this.directory[item.charAt(0).toLowerCase()].push(item);
}
Then I want to display all my items sorted according to their first letter, and I want that first letter to be displayed above the list of items that begin with it, just like a directory. I use the following template in HTML :
<div id="item-list">
<div *ngFor="let entry of directory ; let i = index">
<p>{{i}}</p>
<div *ngFor="let item of entry">
<p>{{item}}</p>
<app-item></app-item>
</div>
</div>
</div>
However, when I run my app, I see no data displayed in HTML. I tried to print text at several points :
<div id="item-list">
<p>Hello</p>
<div *ngFor="let entry of directory ; let i = index">
<p>Hello again</p>
<p>{{i}}</p>
<div *ngFor="let item of entry">
<p>{{item}}</p>
<app-item></app-item>
</div>
</div>
</div>
The webpage displays"Hello", but no "Hello again" (while I think the latter should be printed twice). However, there is absolutely no error message neither when running ng serve nor loading the page. I've searched on the web for a similar problem, but nobody seems to be facing the same difficulties to dynamically display an array of arrays.
Can you tell me what I am doing wrong? Any help would be greatly appreciated. :)