title: How to stop timer in Angularjs2
body: <p>I have set a time interval in my Angularjs2 application as follows. When logout i need to stop this because after logout also i can see my preloader works that means still the function(<code>UpdateTransactions</code>) getting called.</p>
  
  <p>transaction.component.ts</p>
  
  <pre><code>ngOnInit() {
      let timer = Observable.timer(45000,40000);
      timer.subscribe(t=&gt; {
          this.UpdateTransactions();
      });
  }
  </code></pre>
  
  <p>login.component.ts</p>
  
  <pre><code>logout(){
      localStorage.removeItem("token");
      localStorage.removeItem("user");
      localStorage.removeItem("paydid");
  }
  </code></pre>
  
  <p>How can i stop this timer when logout. Help appreciated. Thanks!</p>
  
  <p><strong>Edit</strong></p>
  
  <pre><code>import { Component, OnInit, OnDestroy } from '@angular/core';
  import {TransactionService} from '../services/transaction.service';
  import { HttpClient } from '../providers/http-client';
  import {Transaction} from '../models/transaction';
  import { Router } from '@angular/router';
  import {Observable} from 'rxjs/Rx';
  import {mynum_directives} from '../common/mynum_directives';
  
  @Component({
    selector: 'app-transaction',
    templateUrl: './transaction.component.html',
    styleUrls: ['./transaction.component.css'],
  })
  export class TransactionComponent implements OnInit, OnDestroy {
  
  private transactions:any;
  public errorMsg = 'Transactions update request sent successfully!';
  public timer;
  
    constructor(private _service:TransactionService, private _router: Router )    { 
    }
  
    ngOnInit() {
      this.timer = Observable.timer(45000,40000);
      this.timer.subscribe(t=&gt; {
      this.UpdateTransactions();
    });
   }
  
   ngOnDestroy() {
     this.timer.unsubscribe();
   }
  
   UpdateTransactions(){
     ////some stuff
   }
  
  }
  </code></pre>