title: Angular2 setinterval
body: <p>I use setInterval in angular2 but dont work please help. If i call a function show error. I want to update data of page as ajax and i use setinterval</p>
  
  <pre><code>export class AppComponent{ 
  
    objMonitoring: Monitoring = new Monitoring();
    arrMonitoring: Monitoring[]=[];
  
  
    constructor(private httpService: HttpService){}
  
    public sampleMethodCall() {
       setInterval(function() {
         this.ngOnInit(); },4000); 
       }
  
    ngOnInit(){
      this.httpService.getData().subscribe((data: Response) =&gt; {
        let monitoringList = data.json();
        this.arrMonitoring = [];   
        for(let index in monitoringList){
          this.arrMonitoring.push(monitoringList[index]);
        }
     });
   }
  </code></pre>
  
  <p>In template i call function this code </p>
  
  <pre><code> &lt;button (click)="sampleMethodCall()"&gt;click&lt;/button&gt;
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/CakUi.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/CakUi.png" alt="enter image description here"></a></p>