title: SetTimeout in Angular 5 Service
body: <p>I want to have a property <code>currentAndLastVehicles</code> in my service, which will be automatically change every second.</p>
  
  <p>So far:</p>
  
  <pre><code>import { Injectable } from '@angular/core';
  
  @Injectable()
  export class SharedDataService {
  
    constructor() {
      setTimeout(() =&gt; {
        console.log("hello");
        this.currentAndLastVehicles = [(Math.floor(Math.random() * (1000000 - 9999999)) + 9999999).toString(),...this.currentAndLastVehicles];
      }, 1000);
    }
  
    public currentAndLastVehicles : string[] = [];
  }
  </code></pre>
  
  <p>Problems:</p>
  
  <ul>
  <li>setTimeout will only be executed once (most likely because <code>setTimeout</code> is located in the constructor)</li>
  <li><code>setTimeout</code> outside of the constructor leads multiple errors</li>
  </ul>
  
  <p>What can I do to achieve the desired behaviour? </p>