title: Angular: can we return a string from a service and display it in multiple components?
body: <p>I have a service and a method in it which returns a string, on ngOnInIt() that method gets called, but I'm trying to put that returned value in a variable to display in template.</p>
  
  <p>Tried using observable but didn't help so far</p>
  
  <p><strong>Service</strong>:</p>
  
  <pre><code>FetchUsername() {
  
  this.http.post("http://localhost:3000/fetch_name", {email: 
  "sid@Yahoo.com"}).subscribe(
    success =&gt; {   
  
      var success_json = success.json();
  
      // console.log(success_json.message);
  
      return success_json.message;
  
    },
    error =&gt; {console.log(error)}
  )
  
  }
  </code></pre>
  
  <p><strong>Component.ts</strong>:</p>
  
  <pre><code>username: string; 
  
  ngOnInit() {
      this.username = this.crudService.FetchUsername();
  }
  </code></pre>
  
  <p>Can I ?</p>
  
  <ul>
  <li>call the service once, store the resultant value from HTTP call in a variable in that service;</li>
  <li>from other components, I would no longer need the HTTP call and can just read from that variable instead of having to call the service again and again</li>
  </ul>