mercredi 25 novembre 2020

How to detect if an element is checked or unchecked in mutiselect Angular

I'm working with and for every checked element i create a button, so i have a list where i should add button when check and delete it when uncheck. For this code in every action there is an added button, what should i change, or how to separate the check action from the uncheck

// on change function
check(event): void {
     this.selectedLanguages.forEach(lang => {
        const button = new Button();
        const style =  new ButtonStyle();
        button.name =  lang.name;
        button.style = style;
        this.buttons.push(button);
    });
}


//html
<p-multiSelect [options]="languages" [(ngModel)]="selectedLanguages" (onChange)="test($event)" defaultLabel="Select a Language" optionLabel="name" class="multiselect-custom">
        <ng-template let-value pTemplate="selectedItems">
            <div *ngIf="!selectedLanguages || selectedLanguages.length === 0" class="country-placeholder">
                Select Languages
            </div>
        </ng-template>
        <ng-template let-language pTemplate="item">
            <div class="country-item">
                <img src="assets/showcase/images/demo/flag/flag_placeholder.png" [class]="'flag flag-' + language.value.code.toLowerCase()" />
                <div></div>
            </div>
        </ng-template>
    </p-multiSelect>



Aucun commentaire:

Enregistrer un commentaire