jay
jay

Reputation: 87

How to create toggle buttons generated by for loops in angular 4/6

I have created this demo, in which I have three buttons. These are generated through for loop running on backend response.

all the buttons are clickable and turning activate and deactivate with click event but what logic should I have to use to make only one button active at a time. (it should work like toggle button but these are not the toggle buttons)

so the selection of anyone button will make other 2 deactivate.

Please see the demo code on like below,

updated code / current working logic

Upvotes: 0

Views: 1095

Answers (1)

Vivek Kumar
Vivek Kumar

Reputation: 5040

I have modified the code, make it like this

  someMethod(something) {
    this.groupOfButton.forEach(btn => {
       btn['active'] = (btn.number === something.number);
    });
  }

Upvotes: 1

Related Questions