I am currently working on a component that lists items with a dropdown option to change values. However, I have noticed a small issue where the selected item in the dropdown appears empty upon component creation. The selection only becomes visible after clicking elsewhere on the page.
Typescript
export class Component {
@Input() files: ProductFile[];
contentTypes: { [id: string]: string } = {};
ngOnInit(): void {
this.files.forEach(file => this.contentTypes[file.id] = file.contentType);
}
public fileTypes: string[] = [/* items in the dropdown */];
}
HTML
<div
*ngFor="let file of files"
class="file shadow"
>
<dy-dropdown
[items]="fileTypes"
[ngModel]="contentTypes[file.id]"
(ngModelChange)="onUpdate($event, file)"
></dy-dropdown>
</div>
P.S.: dy-dropdown
refers to a custom Form Control designed to update the value whenever an item is selected from the dropdown list.