title: Angular Cannot Read Property of Undefined Loop Through Array
body: <p>I'm trying to iterate through an Array infinitely with a 4 second interval. It's executing the function every 4 seconds but I'm getting the following logged in the console:</p>
  
  <ul>
  <li>wemadeit</li>
  <li>undefined</li>
  <li>ERROR TypeError: Cannot read property 'undefined' of undefined</li>
  </ul>
  
  <pre><code>export class TechnologiesComponent implements OnInit {
  
    public slideInState: String = 'in';
  
    public test1Show: Boolean = true;
    public test2Show: Boolean = false;
  
    private counter: number = 0;
    private imgArray: Array&lt;boolean&gt; = [false, false, false, false];
  
    constructor() { }
  
    ngOnInit() {
      setInterval(this.imgCycle, 4000);
    }
  
    imgCycle() {
      console.log('wemadeit')
      console.log(this.counter)
      console.log(this.imgArray[this.counter])
      this.imgArray[this.counter] = true;
      if (this.counter == this.imgArray.length) {
        this.counter = 0
        console.log('reset')
      } else {
        this.counter++
        console.log('+1')
      }
    }
  
  }
  
  </code></pre>