title: Angular 2 add/remove/select all - item from array
body: <p>I want to make a simple selection of items - where people could select from my <code>Array(a)</code> and add to <code>Array(b)</code>. Also they can remove from <code>Array(b)</code> and they can select all <code>Array(a)</code> to <code>Array(b)</code> - then deselect the unwanted. Simply : </p>
  
  <blockquote>
    <p>1.Array(a).item.clicked --> Array(b).item added</p>
    
    <p>2.Array(a).item.clicked 2nd time --> Array(b).item.deleted</p>
    
    <p>3.Array(a).selectAll = Array(b) { if(selected.all) { Array(a).item.clicked --> Array(b).item.removed   } }</p>
  </blockquote>
  
  <p>My start (example with explanation) : </p>
  
  <pre><code>oneFunctionForAll(){
      if(clicked-first-tiem) {
        addCompare(item)
        }
      }
      if(clicked-second-time){
    removeCompore(item, i)
      }
  
      if(selected-all-and-clicked) {
        removeCompore(item, i)
      }
  
  if(selected-all-and-clicked 2nd-time) {
    addCompare(item)
  }
  
    }
    addCompare(item) {
      this.compare.push(item)
      console.log('Prideda',this.compare)
    }
  
    removeCompore(item, i) {
      const index = this.compare.indexOf(i)
      if (index !== -1) {
        this.compare.splice(index, 1);
      }
      console.log('triname',this.compare)
  
    } 
  </code></pre>
  
  <p>HTML : </p>
  
  <pre><code>    &lt;ion-card *ngFor="let item of jsonObj | slice:0:4; let i = index" 
  class="relative" (click)="oneFunctionForAll(item,i);"&gt; &lt;/ion-card&gt;
  </code></pre>
  
  <p>If you have some ideas or done it before, I would like to see how you implemented this. I am struggling now for some reason. Please write if need more information - I will provide it.</p>