S
S
Skrolea2016-02-25 09:45:23
JavaScript
Skrolea, 2016-02-25 09:45:23

How to mark all pressed buttons?

Good afternoon. Morning goof.
There is a "form" on which the user must mark the required colors

<button md-button  md-raised-button 
        *ngFor="#color of colors"
   [class.selected]="color === selectedColors"
    (click)="onSelect(color)">
    {{color.name}}
  </button>

On click, I push it into an array
//When click on color   
   onSelect(color: Color) {
          // choosen color    
        this.selectedColors = color;
          // if exist push color's id in array
                if (this.selectedColors) {
                     this.colorsArray.push(this.selectedColors.id);
                       }
             }

I need to mark "selected" all the buttons that were pressed (and then, by clicking on them, do a slice from the colorsArray array), and now my buttons are "switched". I confess, I took an example from the tour of heroes and fell into a stupor.
Here is an example

Answer the question

In order to leave comments, you need to log in

2 answer(s)
L
lega, 2016-02-25
@lega

jsfiddle.net/lega911/61yy8b8g

J
Justin Bieber, 2016-02-25
@JustinBieber

at htmlacademy, I remember the lesson was like this, but I forgot))

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question