How to remove select options for angular primeng dropdown

Discussão em 'Angular' iniciado por devzero, Fevereiro 18, 2025.

  1. devzero

    devzero Guest

    I'm trying to remove an item from a primeng drowdown

    Init

    ngOnInit() {
    this.characterList = [
    {
    "label":"Select character",
    "id":"-1"
    },
    {
    "label":"New",
    "id":"0"
    },
    {
    "id":32,
    "label":"Test2 "
    }
    ]
    this.character = {
    "id":"32",
    "label":"Test2 "
    }
    }


    The delete function

    delete(): void {
    this.characterList.forEach((item, index) => {
    if (+this.character.id === +item.id)
    this.characterList.splice(index, 1);
    });
    }


    The html:

    <p-dropdown [options]="characterList" [(ngModel)]="selectedCharacter" (onChange)="selectCharacter($event)" optionLabel="label"></p-dropdown>
    <button pButton type="button" label="Delete character" (click)="delete()"></button>


    But for some reason the p-dropdown isn't updated. What am I doing wrong?

    Continue reading...

Compartilhe esta Página