post方法后在Ionic中未执行代码

时间:2019-06-03 09:33:33

标签: angular ionic-framework login

我已经发布到我的API,并且一切正常(获取网络类等)。但是,在我调用该方法之后,其余代码将无法执行。

Login.ts 

login() {
    this.authService.login(this.email, this.pw).subscribe(result => {
      if (result) {
        console.log('Working');
        this.presentLoading();
        // store jwt
        // move to dashboard
        console.log('Valid User');
        this.navCtrl.navigateForward('/menu/first/tabs/tab1');
        this.router.navigate(['/menu/first']);
          }
      },  error => {
          if (error.status === 401) {
            console.log('Authorisation Required');
          }
        }
      );
  }


auth-service.ts

login(email, pw) {
  if (email === '' || pw === '') {
    this.presentAlert();
  } else {
  const params = new HttpParams()
  .set('email', email)
  .set('pw', pw);
  return this.http.post<any>(apiUrl + 'login', {email, pw}, {params});
  }
}

1 个答案:

答案 0 :(得分:0)

尝试一下:

login(email, pw) {

  return this.http.get(apiUrl + "login?"+"email="+email+"pw="+pw)
         .map(res => res.json())
  }
}
login.ts

验证电子邮件和密码