Angular Ionic3财产';捕捉';不存在于类型';承诺式<;无效>';
如何解决这些问题ionic3中的“PromiseLike”类型上不存在属性“catch”。 这里我添加了代码Angular Ionic3财产';捕捉';不存在于类型';承诺式<;无效>';,angular,ionic-framework,ionic3,angularfire2,Angular,Ionic Framework,Ionic3,Angularfire2,如何解决这些问题ionic3中的“PromiseLike”类型上不存在属性“catch”。 这里我添加了代码 adduser(newuser) { var promise = new Promise((resolve, reject) => { this.afireauth.auth.createUserWithEmailAndPassword(newuser.email, newuser.password).then(() => { this.afireauth.au
adduser(newuser) {
var promise = new Promise((resolve, reject) => {
this.afireauth.auth.createUserWithEmailAndPassword(newuser.email,
newuser.password).then(() => {
this.afireauth.auth.currentUser.updateProfile({
displayName: newuser.displayName,
photoURL: ''
}).then(() => {
this.firedata.child(this.afireauth.auth.currentUser.uid)({
uid: this.afireauth.auth.currentUser.uid,
displayName: newuser.displayName,
photoURL: 'give a dummy placeholder url here'
}).then(() => {
resolve({ success: true });
}).catch((err) => {
reject(err);
})
}).catch((err) => {
reject(err);
})
}).catch((err) => {
reject(err);
})
})
return promise;
}
我不知道如何解决这个问题
当我运行爱奥尼亚发球
时,它工作正常
但是,当我运行ionic cordova run android时,它显示了以下问题:类型“PromiseLike”上不存在属性“catch”。类似PromiseLike的对象(表)可能没有catch
方法,这就是错误所说的。它们需要转换为带有Promise.resolve
的承诺,才能像通常的承诺一样使用。请注意,catch
是第二个then
参数的语法糖,并且可以单独与then
一起使用,尽管方法结果仍然应该转换为承诺
代码使用承诺构造反模式。一旦有了承诺,就不需要使用新承诺了:
adduser(newuser) {
returnPromise.resolve(this.afireauth.auth.createUserWithEmailAndPassword(newuser.email,
newuser.password)).then(() => { return Promise.resolve(...) });
}
这在async..wait
中效果更好,因为它自然地将结果转换为承诺:
async adduser(newuser) {
await this.afireauth.auth.createUserWithEmailAndPassword(newuser.email,
newuser.password);
await this.afireauth.auth.currentUser.updateProfile(...);
await this.firedata.child(this.afireauth.auth.currentUser.uid).set(...);
return { success: true };
}
我通过添加push()和set方法解决了这个问题有什么想法吗?@utpauli我不知道如何使用这个?
async
函数应该按照提供的方式使用。某些方法参数已替换为。。。为了可读性。这太棒了@vignesh