I have a component, that displays a list of items. On every item, there is a dropdown with which you can change a value. The only issue is, that when creating the component, the selected item in the dropdown is empty. It appears only if I click anywhere on the page.
Typescript
export class Component {
@Input() files: ProductFile[];
contentTypes: { [id: string]: string } = {};
ngOnInit(): void {
this.files.forEach(f => this.contentTypes[f._id] = f.contentType);
}
public fileTypes: string[] = [/* items in the dropdown */];
}
HTML
<div
*ngFor="let f of files"
class="file shadow"
>
<dy-dropdown
[items]="fileTypes"
[ngModel]="contentTypes[f._id]"
(ngModelChange)="onUpdate($event, f)"
></dy-dropdown>
</div>
P.S.: dy-dropdown
is a custom Form Control which simply changes the value when the user selects an item in the dropdown list.