title: Angular 2 Send callback service to component
body: <p>Hi everybody I have searching hours around and tried everything such like <a href="https://stackoverflow.com/questions/34376854/delegation-eventemitter-or-observable-in-angular2/35568924#35568924">BehaviorSubject or ReplaySube</a> or with <a href="https://ionicframework.com/docs/v2/api/util/Events/" rel="nofollow noreferrer">Events</a> but unsuccessfull .. </p>
  
  <h1>Problem</h1>
  
  <p>I have a Profile Page in which is a button <code>loginFb()</code> which calls my users.services. This Service calls data with FacebookAPI and send them to database.. NOW it would be cool to send back a "callback" to my component with <strong>user</strong> object :) </p>
  
  <p>Because when I (click) on login, I see the new User in Firebase but my page is not "refreshed", I think it's because my async is too late.. ? </p>
  
  <p>Here is my profile.ts (ProfilePage)</p>
  
  <pre><code>import { Users } from '../../services/users.service';
  
  export class ProfilePage {
      user :any;
      isConnected :boolean = false;
  
    constructor(public navCtrl: NavController, 
                public usersService: Users, 
                public modalCtrl: ModalController) { }
  
    loginFB(){
      this.usersService.registerUserFb();
      this.usersService.getUserFacebook().subscribe((userObject) =&gt; {
         this.user = userObject;
        })
      }
  }
  </code></pre>
  
  <p>And here my users.services.ts </p>
  
  <pre><code>  getUserFacebookId(){
     Facebook.getLoginStatus().then((response) =&gt; {
       alert("id in getUSERFACEBOOKID = " + JSON.stringify(response.authResponse.userID));
        return response.authResponse.userID;
      });
    }
  
    getUserFacebook(){
      return this.af.database.object('users/' + this.getUserFacebookId());
    }
  
  registerUserFb(){
      Facebook.login(['email']).then((response) =&gt; {
        Facebook.getLoginStatus().then((response) =&gt; {
          if(response.status == 'connected'){
            this.checkIfUserExists(response.authResponse.userID);
           }
  
          });
        });
    }
  
  checkIfUserExists(uid) {
      let user = this.af.database.object('users/' + uid, { preserveSnapshot: true });
      user.subscribe(snapshot =&gt; {
      if(!snapshot.exists()) {
        this.saveInDatabase(uid);
      }
      });
  }
  
  saveInDatabase(uid){
        Facebook.api('/' + uid + 
                '?fields=id, name, ...])
              .then((data) =&gt; {
                  var newUser = {
                    //data saving
                  };
                  this.af.database.object('users/' + uid).set(newUser);
                  this.showToast("User successfully registered");
      });
    }
  </code></pre>