Hide Buttons

Asked

Viewed 382 times

-2

Wanted a help with angular, I use an ngFor to generate the buttons "-" and "+" which are the buttons that give choice to the user. So when it comes to choosing options such as the flavor of the pizza I wanted when it clicked on some flavor that "+" button would disappear.. understand ?

<ion-list *ngIf="varia.eMax > 1">
<ng-container *ngFor="let item of itensVaria">
    <ion-item class="compact" *ngIf="item.idPV == varia.idPV">
      <ion-row no-padding>
        <ion-col col-7 style="text-align: left;">
          <h2 class="h2">Descrião do item</h2>

        </ion-col>

        <ion-col col-5>
          <button ion-button icon-only clear color="danger" (click)="changeQty(item, varia, -1)">
            <ion-icon name="remove-circle"></ion-icon>
          </button>

          <!-- <button ion-button clear color="danger"> qtd do item </button> -->

          <button ion-button icon-only clear color="danger" (click)="changeQty(item, varia, 1)">
            <ion-icon name="add-circle"></ion-icon>
          </button>
        </ion-col>
      </ion-row>

    </ion-item>
</ng-container>

But as there are several flavors and the user can choose only at most 3 and at least 2 for example I wanted to click x flavor the button related to this flavor is unavailable indicating that he has already clicked on this flavor!

1 answer

0


Would it be possible for you to have a variable with the flavors added.:

saboresAdicionados = [];

And put on the button a disabled calling a tasty method (item)

<button ion-button [disabled]="saborJaAdicionado(item)" icon-only clear color="danger" (click)="changeQty(item, varia, 1)">
 <ion-icon name="add-circle"></ion-icon>
</button>

The method could be as follows:

saborJaAdicionado(item){
    let achouItem = false;
    this.saboresAdicionados.foreach(e => { 
       if (e === item) achouItem = true;
    }
    return achouItem;
}

This way for each item it will test if the flavor is already added and will make the release/blocking of the flavor.

  • I edited the question that way I know how to do it, but leave with everyone I want you to do according to the item!

  • @Sigautomation updated the answer

  • It didn’t work. It’s a mistake;Typescript Error&#xA;Property 'includes' does not exist on type 'any[]'.

  • @Sigautomation passed the wrong code, Sorry. includes is only for string

  • @Sigautomation posted the right copy.

  • Thank you was very good.... now how do I show the quantity referred between a button and another ?

  • @Sigautomation sorry, I did not understand what you meant by the quantity referred.

  • Example: when I click on the button it adds the item right? Then I wanted it to show the amount of each item between a button and another. in my code above has a commented part between the two buttons!

  • You can add + that once the same item?

  • yes............

  • @Sigautomation if you can open another question by posting the code of your changeQty function that is easier

  • ai is the link to the question https://answall.com/questions/318728/mostar-quantidades-chosen

Show 7 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.