2017-08-01 64 views
0

代码:属性,则无法在类型为void,A打字稿错误存在

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'); 
    } 
    }) 
} 

错误:

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

有人可以通过纠正这个代码片断帮助我,使“然后”功能作品 欢呼!

+2

的[。然后不会在角2型空隙存在]可能的复制(https://stackoverflow.com/questions/ 45420733/then-does-exist-in-type-void-in-angular-2) – echonax

+1

为什么你再次发布相同的问题? – Sreemat

+0

我无法解决我的查询,因为我不知道什么应该作为参数在复位功能 –

回答

2

这里的问题是passwordreset()功能,

它应该是这样的:

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() ,

请看看你的代码和更新的代码,你会得到一个想法

您的代码:

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

更新的代码:

passwordreset(email): Promise<any> 
{ 
     return new promise((resolve,reject)=>{ 
      firebase.auth().sendPasswordResetEmail(email).then(()=>{ 
           resolve({success :true}); 
          }) 
          .catch((err)=>{ 
           reject(err); 
          }); 
     }); 
} 
相关问题