title: How to implement behavior subject using service in Angular 8
body: <p>I'm new to Angular and I'm having an issue. </p>
  
  <p>I'm creating an app with several sibling components. When I update a value in one component other components don't update. I know that to resolve this issue I should use <em>behaviour subject</em>. But how do I implement it with my service, the components and all the templates?</p>
  
  <p>Here is my code -</p>
  
  <p>----------------------<strong>My service</strong>---------------------------</p>
  
  <pre><code>//import
  
  
  @Injectable() 
  export class CoachService {
  
      apiURL = environment.apiURL;
  
      constructor(private http: HttpClient ) { }
  
      coachProfile(token :string)
      {  
      return this.http.post&lt;any&gt;(this.apiURL+'/coach/profile_infos',{
        token: token
        })        
      }
  
      updateProfile(info: any, token: string, us_id: string) {
        return this.http.post&lt;any[]&gt;(this.apiURL + '/coach/update_profile', {
          token: token,
          us_id: us_id,
          us_lang: info.us_lang,
          us_firstname: info.us_firstname,
          us_lastname: info.us_lastname,
          us_sex: info.us_sex,
          us_birthdate: info.us_birthdate,
          us_national_number : info.us_national_number,
          us_email: info.us_email,
          us_gsm: info.us_gsm,        
          online_profile: info.online_profile,          
          us_address: info.us_address,
          us_zip: info.us_zip,
          us_city: info.us_city,
          country:{
            id: info.country.id
          }
          })
  
      } 
  
  }
  </code></pre>
  
  <p>----------<strong>one component.ts</strong>-------------------</p>
  
  <pre><code>//import
  //component decorator
  
  export class CoordonneesComponent implements OnInit, OnDestroy {
  
  private coachProfile;
    token: string = localStorage.getItem('token');
    us_id : string;
    us_lang: string; 
    infos_profile: any;
    online: any;
  
  
    constructor(private translate: TranslateService,private coachService: CoachService, private router: Router) { }
  
    ngOnInit() {
  
      this.coachProfile=this.coachService.coachProfile(this.token)
        .subscribe((data) =&gt; {
          this.infos_profile = data.results;
          this.online = this.infos_profile.online_profile;
          this.translate.use(this.infos_profile.us_lang)
          this.infos_profile.lang= this.infos_profile.us_lang;
  
        });
  
     .....
    }
  
  
  updateCoordonees() {
    this.coachService.updateProfile(this.infos_profile, this.token, this.us_id)
      .subscribe((data: any) =&gt; {
  
        if(data.success &amp;&amp; data.msg!=null)
        { 
    // do something
        }
        else
        {
         // do something
        }
  
      },
        (err) =&gt; {
          // do something
        });
  
  }  
  
  
  
    ngOnDestroy() {
      this.countrieList.unsubscribe();
      this.coachProfile.unsubscribe();  
    }
  
  
  }
  
  </code></pre>