8

Code:

 reset(){
  let alert = this.AlertCtrl.create({
    buttons :['ok']
  });
  this.userservice.passwordreset(this.email).then((res: any)=>{
    if(res.success){
      alert.setTitle('Email sent');
      alert.setSubTitle('please follow the instructions in the email to reset the password')

    }
    else{
      alert.setTitle('failed');
    }
  })
}

Error:

property then does not exist on type void , A typescript error

can someone please help me by correcting this code snippet so that the 'then' function works cheers!

Pravitha V
  • 3,308
  • 4
  • 33
  • 51
Kanav Malik
  • 143
  • 1
  • 1
  • 12
  • 2
    Possible duplicate of [.then does not exist in type void in angular 2](https://stackoverflow.com/questions/45420733/then-does-not-exist-in-type-void-in-angular-2) – eko Aug 01 '17 at 04:28
  • i am not able to resolve my query as i do not know what should be passed as parameters in the reset function – Kanav Malik Aug 01 '17 at 04:37
  • This is typescript not javascript. Learn the difference. Things of type `void` do not have properties – smac89 Aug 01 '17 at 04:38
  • Will you please post the code of passwordreset ? – Vivek Doshi Aug 01 '17 at 04:38
  • Can you add some code from your service, what is it returning? – Faizal Shap Aug 01 '17 at 04:39
  • passwordreset(email){ var promise = new promise((resolve,reject)=>{ firebase.auth().sendPasswordResetEmail(email).then(()=>{ resolve({success :true}); }).catch((err)=>{ reject(err); }) return promise; }); }this is the service – Kanav Malik Aug 01 '17 at 04:42

2 Answers2

11

The issues here is with passwordreset() function ,

It should look like this :

passwordreset(): Promise<any> {
  // this should return a promise
  // make sure , you are returning promise from here
  return this.http.get(url)
             .toPromise()
             .then(response => response.json().data)
             .catch(this.handleError);
}

You were returning the promise inside promise function , but not returning it from passwordreset(),

Please have a look at your code and updated code , you will get an idea

Your code :

passwordreset(email)
{ 
        var promise = new Promise((resolve,reject)=>{ 
            firebase.auth().sendPasswordResetEmail(email).then(()=>{ 
                            resolve({success :true}); 
                            })
                            .catch((err)=>{ 
                                reject(err); 
                            }) 
                            return promise; 
        }); 
}

Updated Code :

passwordreset(email): Promise<any>
{ 
        return new Promise((resolve,reject)=>{ 
            firebase.auth().sendPasswordResetEmail(email).then(()=>{ 
                                resolve({success :true}); 
                            })
                            .catch((err)=>{ 
                                reject(err); 
                            }); 
        }); 
}
What Would Be Cool
  • 6,204
  • 5
  • 45
  • 42
Vivek Doshi
  • 56,649
  • 12
  • 110
  • 122
0

I handle using this

singlesender(data){

return new Promise((resolve,reject)=>{ 
  this.userService.getAccessToken().then(accesstokendata=>{
    this.accesstoken=accesstokendata;
    console.log(this.accesstoken);
    console.log("hello");

    console.log("hello2");
    let dataToSend = new HttpParams()
      .set("senderidforme", data.senderidforme)  

    let header = new HttpHeaders()
    .set("Content-type", "application/x-www-form-urlencoded")
    .set("Authorization", "Bearer "+this.accesstoken);

      return this.get(SERVER_URL+"web/v2/user-message-unreadcountsignle", dataToSend, header);
  })
  .catch(error=>{

  })


}); 


      }