Felipe XST
Felipe XST

Reputation: 151

Dynamic Click Ionic

I'm getting a list of segment buttons from the database. It's all correct. Now I need to add a click on each segment button. My function click is :

selecionaSubcategorias(pcategoria: string): void {

    this.db.getSubcategorias(pcategoria)
      .then((data) => {

        if (data.length === 0) { 

        }
        else {
          this.subcategorias = data;
          console.log('subcategs', data);
        }
      })
      .catch();
}
<ion-segment *ngIf="categorias" [(ngModel)]="Menu" class="SwipedTabs-tabs">
    <ion-segment-button *ngFor="let categoria of categorias"
                        value={{categoria.nom_categoria}}
                        (click)="selecionaSubcategorias('1')">
        <ion-icon name={{categoria.nom_icon}} class="icon-agendacultural">
        </ion-icon>
    </ion-segment-button>
</ion-segment>

Certainly I'm only getting category values ('1'). How can I receive per click the value of the click of each category?

Upvotes: 0

Views: 381

Answers (1)

Felipe XST
Felipe XST

Reputation: 151

I solved by adding the ID as parameter to the click

<ion-segment-button *ngFor="let categoria of categorias"
     value={{categoria.nom_categoria}}

          (click)="selecionaSubcategorias(categoria.id)">   <!-- Here -->

    <ion-icon name={{categoria.nom_icon}} class="icon-agendacultural">
    </ion-icon>
</ion-segment-button>

Upvotes: 1

Related Questions