Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/30.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 错误:属性';然后';不存在于类型';无效';_Angular_Typescript_Firebase_Ionic Framework - Fatal编程技术网

Angular 错误:属性';然后';不存在于类型';无效';

Angular 错误:属性';然后';不存在于类型';无效';,angular,typescript,firebase,ionic-framework,Angular,Typescript,Firebase,Ionic Framework,当用户想要登录到移动应用程序时,我试图从Firebase实时数据库中获取一些用户状态信息(isDeleted:true/false)。尝试此操作时,我遇到以下错误: 类型“void”上不存在属性“then” 代码如下所示: login.page.ts loginUser() { const data = this.loginForm.value; if (!data.userName) { return; } this.loadingCtrl.c

当用户想要登录到移动应用程序时,我试图从Firebase实时数据库中获取一些用户状态信息(isDeleted:true/false)。尝试此操作时,我遇到以下错误:

类型“void”上不存在属性“then”

代码如下所示:

login.page.ts

  loginUser() {
    const data = this.loginForm.value;
    if (!data.userName) {
      return;
    }

    this.loadingCtrl.create({
      message: 'Loading...'
    }).then((res) => {
      res.present();
    });

    const credentials = {
      email: data.userName + this.username_domain,
      password: data.password
    };

    this.authService.loginUser(credentials)
      .then(res => {
        this.userService.setOrgId(res.user.photoURL);
        this.loadingCtrl.dismiss();
        this.router.navigateByUrl('/tabs');

        //The error occours here.
        this.userService.getUserStatus().then((isDeleted: any) => {
          console.log('isDeleted ', isDeleted)
          if (isDeleted) {
            err => {
              this.loadingCtrl.dismiss();
              this.toast = this.toastCtrl.create({
                message: 'Your account is not active anymore.',
                duration: 2000
                  });
              } 
              this.authService.logoutUser()
              .then(async (res) => {
                this.clearLocalData();
                this.navCtrl.navigateRoot('login');
              })
              .catch(error => {
                console.log(error);
              });
          }
        });

      }, err => {
        this.loadingCtrl.dismiss();
        this.toast = this.toastCtrl.create({
          message: err.message,
          duration: 2000
        }).then((toastData) => {
          toastData.present();
        });
      });
    }
getUserStatus() {
   firebase.database().ref(`organizationData/${this.orgId}/users/${this.uId}/isDeleted/`).get().then(function(snapshot) {
      if (snapshot.exists()) {
        console.log(snapshot.val());
      }
      else {
        console.log("No data available");
      }
    }).catch(function(error) {
      console.error(error);
    });
  }
user.service.ts

  loginUser() {
    const data = this.loginForm.value;
    if (!data.userName) {
      return;
    }

    this.loadingCtrl.create({
      message: 'Loading...'
    }).then((res) => {
      res.present();
    });

    const credentials = {
      email: data.userName + this.username_domain,
      password: data.password
    };

    this.authService.loginUser(credentials)
      .then(res => {
        this.userService.setOrgId(res.user.photoURL);
        this.loadingCtrl.dismiss();
        this.router.navigateByUrl('/tabs');

        //The error occours here.
        this.userService.getUserStatus().then((isDeleted: any) => {
          console.log('isDeleted ', isDeleted)
          if (isDeleted) {
            err => {
              this.loadingCtrl.dismiss();
              this.toast = this.toastCtrl.create({
                message: 'Your account is not active anymore.',
                duration: 2000
                  });
              } 
              this.authService.logoutUser()
              .then(async (res) => {
                this.clearLocalData();
                this.navCtrl.navigateRoot('login');
              })
              .catch(error => {
                console.log(error);
              });
          }
        });

      }, err => {
        this.loadingCtrl.dismiss();
        this.toast = this.toastCtrl.create({
          message: err.message,
          duration: 2000
        }).then((toastData) => {
          toastData.present();
        });
      });
    }
getUserStatus() {
   firebase.database().ref(`organizationData/${this.orgId}/users/${this.uId}/isDeleted/`).get().then(function(snapshot) {
      if (snapshot.exists()) {
        console.log(snapshot.val());
      }
      else {
        console.log("No data available");
      }
    }).catch(function(error) {
      console.error(error);
    });
  }
有人知道如何修复它吗?

getUserStatus()
不返回任何内容,您必须执行以下操作:

getUserStatus() : Promise<DataSnapshot> {
   return firebase.database().ref(`organizationData/${this.orgId}/users/${this.uId}/isDeleted/`).get();
  }
getUserStatus():承诺{
返回firebase.database().ref(`organizationData/${this.orgId}/users/${this.uId}/isDeleted/`).get();
}

解决了这个问题。非常感谢Peter。但是现在我没有在login.page.ts函数中添加标志。您可能也有解决方案吗?您是否正在删除此
isDeleted
?我正在获取user.service.ts:51:“true”但login.page.ts:84:“undefined”。对不起,我是TS的新手。您是否如我所说更改了服务功能?尝试使用
。然后((快照:DataSnapshot)=>{