未发现(承诺):错误:没有GooglePlus提供者

col*_*r-j 2 node.js typescript ionic-framework ionic2 angular

我正在尝试使用cordova-plugin-googleplus插件。

我读过其他文章,说要将该插件添加为提供程序,并且尝试这样做无济于事。

当我尝试访问登录页面时,出现带有堆栈跟踪的错误:

未发现运行时错误(承诺):错误:没有GooglePlus提供商!错误:没有GooglePlus提供商!在ReflectiveInjector_处的noProviderError(http:// localhost:8100 / build / vendor.js:1628:12)处,在injectionError(http:// localhost:8100 / build / vendor.js:1590:86)处。在ReflectiveInjector处抛出throwOrNull(http:// localhost:8100 / build / vendor.js:3129:19ReflectiveInjector上的getByKeyDefault(http:// localhost:8100 / build / vendor.js:3168:25ReflectiveInjector .get(http:// localhost:8100 / build / vendor.js:2969:21处的getByKey(http:// localhost:8100 / build / vendor.js:3100:25),位于AppModuleInjector.getInternal(ng:///AppModule/module.ngfactory.js:615:44)的AppModuleInjector.get(ng:///AppModule/module.ngfactory.js:332:145)。在LoginPageModuleInjector.NgModuleInjector.get 获取(http:// localhost:8100 / build / vendor.js:3936:44)(http:// localhost:8100 / build / vendor.js:3937:52

堆栈跟踪

Error: Uncaught (in promise): Error: No provider for GooglePlus!
Error: No provider for GooglePlus!
    at injectionError (http://localhost:8100/build/vendor.js:1590:86)
    at noProviderError (http://localhost:8100/build/vendor.js:1628:12)
    at ReflectiveInjector_._throwOrNull (http://localhost:8100/build/vendor.js:3129:19)
    at ReflectiveInjector_._getByKeyDefault (http://localhost:8100/build/vendor.js:3168:25)
    at ReflectiveInjector_._getByKey (http://localhost:8100/build/vendor.js:3100:25)
    at ReflectiveInjector_.get (http://localhost:8100/build/vendor.js:2969:21)
    at AppModuleInjector.get (ng:///AppModule/module.ngfactory.js:332:145)
    at AppModuleInjector.getInternal (ng:///AppModule/module.ngfactory.js:615:44)
    at AppModuleInjector.NgModuleInjector.get (http://localhost:8100/build/vendor.js:3936:44)
    at LoginPageModuleInjector.NgModuleInjector.get (http://localhost:8100/build/vendor.js:3937:52)
    at c (http://localhost:8100/build/polyfills.js:3:13535)
    at Object.reject (http://localhost:8100/build/polyfills.js:3:12891)
    at NavControllerBase._fireError (http://localhost:8100/build/vendor.js:45902:16)
    at NavControllerBase._failed (http://localhost:8100/build/vendor.js:45890:14)
    at http://localhost:8100/build/vendor.js:45945:59
    at t.invoke (http://localhost:8100/build/polyfills.js:3:9283)
    at Object.onInvoke (http://localhost:8100/build/vendor.js:4508:37)
    at t.invoke (http://localhost:8100/build/polyfills.js:3:9223)
    at r.run (http://localhost:8100/build/polyfills.js:3:4452)
    at http://localhost:8100/build/polyfills.js:3:14076
Run Code Online (Sandbox Code Playgroud)

平台详情

  • 离子框架:3.6.1
  • Ionic应用程序脚本:2.1.4
  • 角核:4.1.3
  • Angular编译器CLI:4.1.3
  • 节点:6.11.2
  • 操作系统平台:Windows 10
  • 导航器平台:Win32用户代理:Mozilla / 5.0(Windows NT 10.0; Win64; x64)AppleWebKit / 537.36(KHTML,如Gecko)Chrome / 60.0.3112.113 Safari / 537.36

Login.ts

import { Component } from '@angular/core';
//import { GooglePlus } from '@ionic-native/google-plus';
import { TranslateService } from '@ngx-translate/core';
import { IonicPage, NavController, ToastController } from 'ionic-angular';

import { User } from '../../providers/providers';
import { MainPage } from '../pages';

@IonicPage()
@Component({
  selector: 'page-login',
  templateUrl: 'login.html'
})
export class LoginPage {
  // The account fields for the login form.
  // If you're using the username field with or without email, make
  // sure to add it to the type
  account: { username: string, password: string } = {
    username: '',
    password: ''
  };

  // Our translated text strings
  private loginErrorString: string;

  constructor(public navCtrl: NavController,
    public user: User,
    public toastCtrl: ToastController,
    public translateService: TranslateService,
//    private GooglePlus: GooglePlus
  ) {

    this.translateService.get('LOGIN_ERROR').subscribe((value) => {
      this.loginErrorString = value;
    })
  }

  // Attempt to login in through our User service
  doLogin() {
    this.user.login_basic(this.account).subscribe((resp) => {
      this.navCtrl.push(MainPage);
    }, (err) => {
      this.navCtrl.push(MainPage);
      // Unable to log in
      let toast = this.toastCtrl.create({
        message: this.loginErrorString,
        duration: 3000,
        position: 'top'
      });
      toast.present();
    });
  }

}
Run Code Online (Sandbox Code Playgroud)

login.module.ts

import { NgModule } from '@angular/core';
import { GooglePlus } from '@ionic-native/google-plus';
import { TranslateModule } from '@ngx-translate/core';
import { IonicPageModule } from 'ionic-angular';

import { LoginPage } from './login';

@NgModule({
  declarations: [
    LoginPage,
  ],
  imports: [
    IonicPageModule.forChild(LoginPage),
    TranslateModule.forChild()
  ],
  exports: [
    LoginPage
  ],
  providers: [
    GooglePlus,
  ],
})
export class LoginPageModule { }
Run Code Online (Sandbox Code Playgroud)

Zeh*_*n12 8

您需要将GooglePlus提供者添加到AppModule(app.module.ts)