We have an enum like
Code: Select all
export enum Status {
UNBLOCKED,
BLOCKED,
DEFECTIVE
}
Now I'd like to have this enum as a source of options for a Dropdown component. I do it as the following:
Code: Select all
<p-dropdown [options]="statuses" [(ngModel)]="selectedStatus" [autoWidth]="false"></p-dropdown>
Where the
statuses and
selectedStatus are the following (setupStatuses is initialized properly):
Code: Select all
statuses: Status[];
selectedStatus: number;
...
ngOnInit(): any {
...
for (let i=0; i<setupStatuses.length; i++) {
this.statuses.push({label: setupStatuses[i], value: i});
}
}
Now, the dropdown list is populated correctly, but the selected item does not correspond to the value in the model. E.g. the selected item in the dropdown always will be UNBLOCKED, regardless of the
selectedStatus initial value. Besides that, the selectedStatus will take the value of the label of the selected item, not the value e.g.
DEFECTIVE. What do I do wrong?