how to wait for a finished method to execute the next in angular?

Well, I'm doing an Angular course, I'm trying to understand the concept of Observables and Promisses, but I'm a little confused, I'm using Firebase to create a simple application, where I use email and password authentication and to save the other user data I have to use the id of this authenticated user and register in the Bank. After that I have to use the method of my service that creates this user and then use the method that saves the data. Following this order I have to make the SignUp(email,senha) method run first than the setUserData(User) method.

> Metodos

SetUserData(user) {
    const itemsRef = this.db.object(`usu/${user.uid}`);
    return itemsRef.set(user);
  }



SignUp(email, password) {
    return this.afAuth.auth.createUserWithEmailAndPassword(email, password)
      .then((result) => {
        this.SendVerificationMail();
        window.alert("BEM VINDO");
      }).catch((error) => {
        window.alert(error.message)
      })
  }

note: the methods are called in the component where I do the two-way data binding with the form using a 'onSubmit ' method'

Author: Junior De Souza, 2019-08-03

2 answers

JS is asynchronous, you can work with callback for this, the first method receives the second method as argument, after the end of processing the first, it ends by calling the second:

function segundo(login) {
  console.log('segundo');
}

function primeiro(callback) {
  console.log('primeiro');
  callback();
}

primeiro(segundo);

Also rolls do this with observable, with promise:

 0
Author: Daniel Mendes, 2019-08-03 16:32:45

What you can do is use subscribe, inside it you make the calls. Subscribe will wait for the function to run and then execute what is inside it. Here's a link to an easier-to-understand tutorial:

 0
Author: Victor Martins, 2019-08-07 13:25:57