2017-07-31 50 views
0

我知道有一個解決方案可用於以下查詢,但我是一個noob在angular2中,不應該在void函數中添加什麼請幫助! enter image description here。然後在角度2中不存在類型void 0

export class PasswordResetPage { 

    email : string; 

    constructor(public navCtrl: NavController, 
       public navParams: NavParams , 
       public userservice :UserProvider, 
       public AlertCtrl :AlertController) { } 

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

你不需要添加任何東西只是將它綁定到一個變量。 –

+1

'passwordReset'顯然不會返回任何東西或者聲明瞭返回類型'void'(即使它返回了某些東西)。 請將代碼作爲文本添加到問題中,而不僅僅是屏幕截圖的鏈接。 –

+0

謝謝你這裏的回覆是代碼, –

回答

0

知道這個服務調用的返回類型是很重要的:如果服務調用返回無極

this.userservice.passwordreset(this.email) 

。然後只適用,它更可能是它的返回一個Observable,所以你需要訂閱它來獲得價值。

this.userservice.passwordreset(this.email) 
.subscribe(
     res => { 
     alert.setTitle('Email sent'); 
     alert.setSubTitle('please follow the instructions in the email to reset the password') 
     }, 
     err => { 
      console.log('Error', err), 
      alert.setTitle('failed') 
     } 
); 
相關問題