Javascript 离子2项目-认证承诺问题

Javascript 离子2项目-认证承诺问题,javascript,angular,ionic2,Javascript,Angular,Ionic2,我一直在寻找解决这个问题的方法,但还没有找到任何适合我的特殊情况的方法。我正在开发一个Ionic 2应用程序,我正在为我的登录屏幕开发一些身份验证功能。这个文件的目的是将后端功能添加到我编写的前端代码中(请参阅下面github链接上的login.html文件)。我一直在关注这个网站上的教程: 我遇到的问题是,对于某些将在代码中标记的函数,我得到一个“从(函数)返回的承诺被忽略”,这会使代码完全无法运行。它不是编译错误,而是运行时错误,即: 运行时错误 未捕获(承诺中):错误:没有Http提供程

我一直在寻找解决这个问题的方法,但还没有找到任何适合我的特殊情况的方法。我正在开发一个Ionic 2应用程序,我正在为我的登录屏幕开发一些身份验证功能。这个文件的目的是将后端功能添加到我编写的前端代码中(请参阅下面github链接上的login.html文件)。我一直在关注这个网站上的教程:

我遇到的问题是,对于某些将在代码中标记的函数,我得到一个“从(函数)返回的承诺被忽略”,这会使代码完全无法运行。它不是编译错误,而是运行时错误,即:

运行时错误 未捕获(承诺中):错误:没有Http提供程序!d处的错误

我真的不知道这意味着什么,所以任何见解都会非常有用。如果需要,我可以提供完整错误的图片

@IonicPage()
@Component({
  selector: 'page-login',
  templateUrl: 'login.html',
})
export class LoginPage {
  loading: Loading;
  registerCredentials = { email: '', password: ''};

  constructor(public navCtrl: NavController, private auth: AuthService, public navParams: NavParams,
  private alertCtrl: AlertController, private loadingCtrl: LoadingController) {}

  public createAccount() {
    this.navCtrl.push('RegisterPage'); //Promise ignored error
  }

  public login() {
    this.showLoading();
    this.auth.login(this.registerCredentials).subscribe(allowed => {
        if (allowed) {
          this.navCtrl.setRoot('HomePage'); //Promise ignored error
        } else {
          this.showError("Access Denied");
        }
      },
      error => {
        this.showError(error);
      });
  }

  showLoading() {
    this.loading = this.loadingCtrl.create({
      content: 'Please wait...',
      dismissOnPageChange: true
    });
    this.loading.present(); //Promise ignored error
  }

  showError(text) {
    this.loading.dismiss(); //Promise ignored error

    let alert = this.alertCtrl.create({
      title: 'Fail',
      subTitle: text,
      buttons: ['OK']
    });
    alert.present(prompt); //Promise ignored error
  }
}
错误图片:

我只是不确定是什么导致了这个问题,它导致我的代码完全崩溃,甚至无法加载我的UI。如果您需要查看其他一些文件,其余文件在我的github上,此特定文件位于/src/pages/login

其余文件:

  • IDE:JetBrains WebStorm
  • 操作系统:MacOS Sierra
  • 爱奥尼亚版本:2.2.2

我不确定这是否能解决您的问题,但请尝试将以下内容添加到您的app.module.ts文件中

import { HttpModule } from '@angular/http';
它可能会修复您的http提供程序错误 您还必须将其添加到同一文件中的导入中

imports: [
    BrowserModule,
    HttpModule,
    CloudModule.forRoot(cloudSettings),
    IonicModule.forRoot(MyApp),
    IonicStorageModule.forRoot()
  ],

您可能已经找到了答案,但请尝试在您的代码中将public更改为private:

constructor(public navCtrl: NavController,
尝试:


您的auth-service.ts中只有一个较小的内容,但缺少一个空间构造函数(publichttp:Http){console.log('Hello AuthService Provider');}此外,您还缺少Login.ts中的RegisterPage导入,请从“../register/register”添加导入{RegisterPage};我还没有完成登录页面,你认为这可能会导致问题吗?它肯定会导致问题,毫无疑问,它是否会解决你所有的问题我不确定,我只是缩小了问题的范围。我在爱奥尼亚测试版上,所以我不能亲自运行你的项目来调试它,所以我只是按照我能看到的去做
constructor(private navCtrl: NavController,