Check if data exist before post


#1

Hi,

As i said i want to check if there’s some data before posting it

connexion(){
  var headers = new Headers();
  headers.append('Content-Type', 'application/x-www-form-urlencoded');
   
  var params = 'email='+this.userData.email+'&passe='+this.userData.passe;
  this.http.post(apiUrl, params , {headers: headers})
  .subscribe(
    data => {
      //console.log(this.responseData),
      this.storage.set('utilisateurData', data);
      this.navCtrl.push('ProfilPage');
    },
    err => {
      console.log(err);
    },
    () => console.log('Call Complete')
  );


#2

which data? you mean this params?
or responseData?


#3

please look into https://angular.io/guide/form-validation and https://ionicframework.com/docs/developer-resources/forms/


#4
conexion() {
    if(this.userData.email && this.userData.passe) {
        [yourCode]
    } else {
        console.error("Missing required data!");
    }
}