原始例外:没有Auth的提供者! :离子云服务

时间:2016-09-21 02:47:07

标签: authentication ionic-framework ionic2

我设置了Ionic Cloud Service并完成了授权用户的初始过程。

import {Component} from '@angular/core';
import {NavController} from 'ionic-angular';
import {Auth, User, UserDetails, IDetailedError} from '@ionic/cloud-angular';

@Component({
  templateUrl: 'build/pages/signup/signup.html'
})
export class SignupPage {

  constructor(public auth: Auth, public user: User){
    let details: UserDetails = {'email': 'hi@ionic.io', 'password': 'puppies123'};

    this.auth.signup(details).then(() => {
      // `this.user` is now registered
    }, (err: IDetailedError<string[]>) => {
      for (let e of err.details) {
        if (e === 'conflict_email') {
          alert('Email already exists.');
        } else {
          // handle other errors
        }
      }
    });
  }

}

出于某种原因,我收到此错误:ORIGINAL EXCEPTION:没有Auth提供商! 原装STACKTRACE: 错误:DI异常

所有设置都像离子云文档建议的那样:https://docs.ionic.io/services/auth/#setup

我到处寻找这个答案

3 个答案:

答案 0 :(得分:4)

在设置说明中,它讨论了如何将离子云NgModule添加到模块的导入中:

https://docs.ionic.io/setup.html

import { CloudSettings, CloudModule } from '@ionic/cloud-angular';

const cloudSettings: CloudSettings = {
  'core': {
    'app_id': 'APP_ID'
  }
};

@NgModule({
  declarations: [ ... ],
  imports: [
    IonicModule.forRoot(MyApp),
    CloudModule.forRoot(cloudSettings)
  ],
  bootstrap: [IonicApp],
  entryComponents: [ ... ],
  providers: [ ... ]
})
export class AppModule {}

我错过了这些步骤。进行此更改可以解决问题。

答案 1 :(得分:0)

试试这个

@Component({
  templateUrl: 'build/pages/signup/signup.html',
  providers: [Auth]
})

不确定它是否有效,因为离子文档对此没有任何说明,但看​​起来似乎是合乎逻辑的错误

答案 2 :(得分:0)

Auth中传递providers,开始在控制台中显示错误:

Cannot read property 'config' of undefined