title: How to return in Angular 8 with Observable and pipe()?
body: <p>I use my own data service in Angular with a <code>save()</code> method witch can run create or update on server side. But before send datas to server it's need to be check datas are valid or not.</p>
  
  <p>If data isn't valid, the communication to the server will not happen.</p>
  
  <p>Here is the code:</p>
  
  <pre class="lang-js prettyprint-override"><code>  save(data: T): Observable&lt;boolean&gt; {
      const preparedData = JSON.stringify(data.prepareToSave());
  
      if (!data.isValid) {
        // if data is invalid we should return before send datas to server
        return new Observable&lt;T&gt;().pipe(map(() =&gt; false));
      }
  
      if (!data.id) {
        // create
        return this.http.post(this.url, preparedData, this.options)
          .pipe(map(() =&gt; true));
      } else {
        // update
        return this.http.put(this.url + '/' + data.id, preparedData, this.options)
          .pipe(map(() =&gt; true));
      }
    }
  </code></pre>
  
  <p>Now if the <code>data</code> isn't valid I need to return an <code>Observable&lt;boolean&gt;</code> with <code>false</code>.</p>
  
  <p>In the component I have this code:</p>
  
  <pre class="lang-js prettyprint-override"><code>  saveDatas() {
      this.dataService.save(this.customer).subscribe( (resolve: boolean) =&gt; {
        if (resolve) {
          // save OK
        } else {
          // save failed (1)
        }
      }, (error: any) =&gt; {
        // save failed (2)
      });
    }
  </code></pre>
  
  <p>If the save fails because of <code>this.customer.isValid</code> is <code>false</code> then I expect <code>subscribe</code> will get <code>false</code> from dataService. Exactly from this line:</p>
  
  <pre class="lang-js prettyprint-override"><code>    if (!data.isValid) {
        // if data is invalid we should return before send datas to server
        return new Observable&lt;T&gt;().pipe(map(() =&gt; false));
      }
  </code></pre>
  
  <p>But something goes wrong, and I can't figure out what's the mistake.</p>
  
  <p>Why don't return the data service with <code>false</code>?</p>