.then在角度2的void类型中不存在 [英] .then does not exist in type void in angular 2
本文介绍了.then在角度2的void类型中不存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我知道以下查询有一个解决方案,但我是angular2的新手,不要在void函数中添加什么内容,请帮忙!在此处输入图片描述
I know that there is a solution available to the following query but I am a noob in angular2 and do not what should be added in the void function please Help! enter image description here
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');
}
})
}
}
推荐答案
重要的是要知道此服务调用的返回类型是什么:
It's important to know what the return type of this service call is:
this.userservice.passwordreset(this.email)
.然后仅在服务调用返回Promise时才适用,并且更有可能返回Observable,因此您需要订阅该值以获取值.
.then is only applicable if the service call returns a Promise, and it's more likely that it's returning an Observable, so you'd need to subscribe to that to get the value.
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')
}
);
这篇关于.then在角度2的void类型中不存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文