How to create checkbox from enum then get the selected enum value in angular?

Discussão em 'Angular' iniciado por rheza 555, Fevereiro 9, 2025.

  1. rheza 555

    rheza 555 Guest

    Trying to create a few checkbox from enum.

    export enum Tags {
    Sword=<any>"Sword",
    Claymore=<any>"Claymore",
    Bow=<any>"Bow",
    Catalyst=<any>"Catalyst",
    Polearm=<any>"Polearm"
    }


    From this enum is there a way to loop creating checkbox with angular? I found these but cannot get the values back. This is in the component.

    tagsText = Object.values(Tags);
    getHeroByTags(e:any){
    console.log(e);
    }


    This is in the html.

    <li *ngFor="let tag of tagsText">
    <label>
    <input type="checkbox" (click)="getHeroByTags($event)" value="{{tag}}"/>
    {{tag}}
    </label>
    </li>


    It generate the checkbox with the correct label but it doesn't get the enum value in the function getHeroByTags.

    Continue reading...

Compartilhe esta Página