I've update the code to add support for initial expand conditions:
merge(this.items.changes, of(this.items))
.pipe(map(() => this.items.toArray()))
.subscribe((items) => {
items.forEach((item, index) => {
if (item.expanded) {
this.expanded.add(index);
}
});
this.cdr.detectChanges();
});