title: Catch error in promise from a service in an Angular component
body: <p>Hi everyone running into a problem with a post service I created in angular. Struggling to catch the error from my component when I call the service. I was able to catch the error from the service but I need to do this from my component to properly handle the error. Any advice would be greatly appreciated. </p>
  
  <p><strong>Service</strong></p>
  
  <pre><code>sendData(obj) {
   let promise = new Promise((resolve) =&gt; {
     this.http.post(this.URL, obj, this.httpOptions)
       .toPromise()
       .then(
        res =&gt; {
          console.log(res);
          resolve(res);
        }
       )
       //.catch((err) =&gt; { 
       //  console.log(err);
       //  throw err;
       //});
     });
    return promise;
  }
  </code></pre>
  
  <p><strong>Component</strong></p>
  
  <pre><code>this._myservice.sendData(this.myobj)
    .then(function (res) {
      console.log('data sent');
    })
    .catch(error =&gt; {
        console.warn('from component:', error);
        // this console warn never gets logged out
    });
  </code></pre>
  
  <p>Do I need to update something in my service to allow me to catch the error from the component?</p>