Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/29.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ionic-framework/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular Ionic3财产';捕捉';不存在于类型';承诺式<;无效>';_Angular_Ionic Framework_Ionic3_Angularfire2 - Fatal编程技术网

Angular Ionic3财产';捕捉';不存在于类型';承诺式<;无效>';

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

如何解决这些问题ionic3中的“PromiseLike”类型上不存在属性“catch”。

这里我添加了代码

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