title: how to make functions executes in order
body: <p>I'm making a project using angular and firebase, and I'm facing problem how to make a function to work synchronously .
  So my contrat.ts looks like this:</p>
  
  <pre class="lang-js prettyprint-override"><code>import { Component, OnInit } from '@angular/core';
  import { ContratService } from './contrat.service';
  import { FormBuilder, FormGroup, FormArray} from '@angular/forms'
  
  @Component({
    selector: 'app-contrat',
    templateUrl: './contrat.component.html',
    styleUrls: ['./contrat.component.css']
  }) 
  export class ContratComponent implements OnInit {
    today: number = Date.now();
  
    contrat: FormGroup;
    constructor(private fb:FormBuilder ,private contratService: ContratService) { }
  
    ngOnInit() {
      this.contrat=this.fb.group({
        id_Contrat : [''],
        Montant : [''],
        date : [''],
        id_Client : [''],
        id_Freelancer : [''],
        tache : this.fb.array([this.creatTache()])
      })
  this.contrat.get('date').setValue(this.today);
    }
  
  
  creatTache():FormGroup{
    return this.fb.group({
             tacheName: [''],
             paiement:[''],
             delai:['']
    })
  }
  public get tache(){
    return this.contrat.controls['tache'] as FormArray;
  }
  addTache(){
  this.tache.push(this.creatTache());
  }
  removeTache(i:number){
    this.tache.removeAt(i);
  }
  try1(){
    let m=0;
    for(let t of this.contrat.get('tache').value){
      m= +m + +t.paiement;
     }
  
    this.contrat.get('Montant').setValue(m);
  }
  
   try2(u){
    this.contratService.addContrat(u);
  }
   onSubmit(i){
  this.try1();
  this.try2(i);
  
  }
  
  }
  </code></pre>
  
  <p>in the method try1() I was trying to setValue the 'Montant'<br>
  and in the method try2() I was trying to send the data to firebase</p>
  
  <p>the problem is that try2() executes before try1() </p>