【发布时间】:2017-12-07 10:23:05
【问题描述】:
我一直在寻找解决我遇到的这个问题的方法,但没有找到任何适合我的特殊情况的方法。我正在开发一个 Ionic 2 应用程序,并且正在为我的登录屏幕开发一些身份验证内容。该文件的目的是为我编写的前端代码添加后端功能(请参阅下面 github 链接上的我的 login.html 文件)。我正在关注这个网站上的教程: https://devdactic.com/login-ionic-2/
我遇到的问题是,对于某些将在我的代码中标记的函数,我得到一个“从(函数)返回的承诺被忽略”,这会阻止代码完全运行。它不是编译错误,而是运行时错误:
运行时错误 未捕获(承诺):错误:没有 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。
其余文件: https://github.com/jparr721/Badmeat/tree/master/BadMeat-Ionic/FirstBuild/src
- IDE:JetBrains WebStorm
- 操作系统:MacOS Sierra
- 离子版本:2.2.2
【问题讨论】:
标签: javascript angular ionic2