首页 > 解决方案 > Ionic Angular GooglePlus:NgModule 的提供程序无效

问题描述

我正在尝试将GooglePlus登录集成到带有 Angular 应用程序的 Ionic。

错误:

ERROR 错误:未捕获(承诺中):错误:NgModule 'UsersModule' 的提供程序无效 - 只允许提供 Provider 和 Type 的实例,得到:[Keyboard, ?[object Object]?]

users.module.ts

...
import { GooglePlus } from '@ionic-native/google-plus';

@NgModule({
  declarations: [
    ...
  ],
  entryComponents: [
    ...
  ],
  imports: [
    ...
  ],
  exports: [
    ...
  ],
  providers: [
    ...,
    GooglePlus
  ]
})
export class UsersModule { }

标签: angularionic-frameworkionic4google-plus

解决方案


您需要将导入路径更改为:

import { GooglePlus } from '@ionic-native/google-plus/ngx';

您可能会看到构建错误:

An unhandled exception occurred: The target entry-point "@ionic-native/google-plus" has missing dependencies:
 - @ionic-native/core

只需安装@ionic-native/core依赖项,您就可以开始使用了。

npm install @ionic-native/core

最后一个想法,如果您在使用该 Cordova 插件时遇到问题,另一种选择是@codetrix-studio/capacitor-google-auth. Simon Grimm 有一个很棒的博客How to add Capacitor Google Sign In to your Ionic App,其中描述了让 Google auth 工作所需的所有步骤。


推荐阅读