title: How to create a copy of the initial state of an array?
body: <p>I have ratings, that get fetched from a postgres database and displayed in a table.
  When I edit a rating, I can only add or remove tags to it through a input like element which comes from my "TagInputComponent".</p>
  
  <p>The TagInputComponent looks like this:</p>
  
  <pre><code>import { Component, DoCheck, IterableDiffers, OnInit, Input, Output } from 'angular2/core';
  import * as _ from 'underscore';
  
  @Component({
      selector: 'taginput',
      templateUrl: 'app/shared/taginput.component.html',
      styleUrls: ['assets/stylesheets/taginput.css']
  })
  export class TagInputComponent implements OnInit, DoCheck {
  @Input() tags: string[];
  newTag = '';
  oldTags: string[];
  differ: any;
  
  constructor(differs: IterableDiffers) { 
      this.differ = differs.find([]).create(null);
  }
  
  ngOnInit() { }
  
  ngDoCheck() {
      var changes = this.differ.diff(this.tags);
  
      if (changes) {
          changes.forEachAddedItem(r =&gt; console.log('added ' + r.item));
          changes.forEachRemovedItem(r =&gt; console.log('removed ' + r.item));
      }
  }
  </code></pre>
  
  <p>It gets used in the DataFormComponenet like this:</p>
  
  <pre><code>&lt;taginput [tags]="datapoint.tags"&gt;&lt;/taginput&gt;
  </code></pre>
  
  <p>How do I create a copy of <code>tags</code> to <code>oldTags</code> once it is filled with data?</p>
  
  <p>It noticed that <code>ngOnInit()</code> is too early as the data is not yet there from the service. With <code>ngDoCheck()</code> it always updates to the currentState.</p>
  
  <p>It seems like a simple task, but I just can't find out how to do it.</p>
  
  <hr>
  
  <p>igorzg answer worked for me, although I changed it to my needs. This is what I did:</p>
  
  <pre><code>ngDoCheck() {
      var changes = this.differ.diff(this.tags);
  
      if (changes) {
          if (Array.isArray(changes.collection) &amp;&amp; !this.oldTags) {
              this.oldTags = changes.collection.slice();
          }
  
          changes.forEachAddedItem(r =&gt; console.log('added ' + r.item));
          changes.forEachRemovedItem(r =&gt; console.log('removed ' + r.item));
      }
  }
  </code></pre>