title: How to consume REST API with Angular2?
body: <p>This is my demo code:</p>
  
  <p><strong>products.service.ts</strong> </p>
  
  <pre><code>getProducts(){
   this.headers = new Headers();
   this.headers.append("Content-Type", 'application/json');
   this.headers.append("Authorization", 'Bearer ' + localStorage.getItem('id_token'));
   return this.http.get('http://mydomain.azurewebsites.net/api/products',{headers:headers}).map(res =&gt; res.json().data);
  }
  </code></pre>
  
  <p><strong>products.component.ts</strong></p>
  
  <pre><code>constructor(private productsService: ProductsService) { }
  
  ngOnInit() {
   this.productsService.getProducts().subscribe((res) =&gt; {
      console.log(res); 
   });
  }
  </code></pre>
  
  <p>Is it nescessary to import something in the <code>ngModule</code> decorator to consume a REST API or my code is wrong? I can get the desired data with Postman Chrome Extension but not with Angular 2 code.</p>
  
  <p>I hope to have explained my problem well.</p>
  
  <p><strong><em>Update</em></strong></p>
  
  <p>These are the errors i get:</p>
  
  <p><a href="https://i.stack.imgur.com/tNNGf.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/tNNGf.png" alt="enter image description here"></a></p>