0

I need to make a select with enum, in which a text is shown and the value that it stores in another text. I tried as follows but I get the error:

Element implicitly has an 'any' type because expression of type 'string' can't be used to index type 'typeof UserRole'. No index signature with a parameter of type 'string' was found on type 'typeof UserRole'.ngtsc(7053)

Html (Angular-Material)

export enum UserRole {
  STUDENT = 'Estudiante',
  DIRECTOR = 'Director de carrera',
  AUTHORITY = 'Autoridad',
  FINANCIAL = 'Dirección Financiera'
}
keys = Object.keys;
userRoles = UserRole;

TypeScript

<mat-select  required formControlName="role">
    <mat-option *ngFor="let role of keys(userRoles)" [value]="role">
        {{userRoles[role]}}
    </mat-option>
</mat-select>
  • this may help https://www.cloudhadoop.com/angular-select-enum-data/ – Amir Saleem Jul 11 '21 at 06:03
  • 1
    Does this answer your question? [How can I use ngFor to iterate over Typescript Enum as an array of strings](https://stackoverflow.com/questions/38554562/how-can-i-use-ngfor-to-iterate-over-typescript-enum-as-an-array-of-strings) – naveen Jul 11 '21 at 07:51

0 Answers0