title: TS TypeScript SetInterval - Cannot access functions from inside the timer target function
body: <p>I am trying to call a function from inside a timed function called by setInterval(). </p>
  
  <p>Here is my code:</p>
  
  <pre><code>export class SmileyDirective
  {
  
  FillGraphValues()    
  {
      console.log("FillGraphValues works");      // this works
  }
  
  MyTimer()
  {
      console.log("timer works");      // this works
      this.FillGraphValues();          // this does not work
      FillGraphValues();               // this does not work
  }
  
  draw()
  {
      this.FillGraphValues();    // this works
  
      setInterval(this.MyTimer, 1000);
  }
  } 
  </code></pre>
  
  <p>The App crashes with either:</p>
  
  <pre><code>"this.FillGraphValues is not a function"
  </code></pre>
  
  <p>or</p>
  
  <pre><code>Cannot find name 'FillGraphValues'. Did you mean the instance member 'this.FillGraphValues'?
  </code></pre>
  
  <p>I even tried:</p>
  
  <pre><code>setInterval(function(){MyTimer()}, 1000);
  </code></pre>
  
  <p>and</p>
  
  <pre><code>setInterval(function(){this.MyTimer()}, 1000);
  </code></pre>
  
  <p>But they didn't work.</p>
  
  <p>Many Thanks :)</p>