在初始化 ionic 4 之前无法访问“LoginPageModule”

nao*_*val 5 ionic-framework angular ionic4

我正在尝试为我的 ionic 4 应用程序插入 google 登录信息,每次单击登录按钮时都会遇到问题,它看起来像这样有这样的问题

Cannot access 'LoginPageModule' before initialization
Run Code Online (Sandbox Code Playgroud)

我的 login.page.ts 代码如下所示

import { Component, OnInit } from '@angular/core';
import { NavController } from '@ionic/angular';
import { GooglePlus } from '@ionic-native/google-plus';

@Component({
  selector: 'app-login',
  templateUrl: './login.page.html',
  styleUrls: ['./login.page.scss'],
})
export class LoginPage{

  displayName: any;
  email: any;
  familyName: any;
  givenName: any;
  userId: any;
  imageUrl: any;

  isLoggedIn:boolean = false;

  constructor(
    public navCtrl: NavController,
    public googlePlus: GooglePlus
  ) { }

  login() {
    this.googlePlus.login({})
      .then(res => {
        console.log(res);
        this.displayName = res.displayName;
        this.email = res.email;
        this.familyName = res.familyName;
        this.givenName = res.givenName;
        this.userId = res.userId;
        this.imageUrl = res.imageUrl;
        this.isLoggedIn = true;
      })
      .catch(err => console.error(err));
  }

  logout() {
    this.googlePlus.logout()
      .then(res => {
        console.log(res);
        this.displayName = "";
        this.email = "";
        this.familyName = "";
        this.givenName = "";
        this.userId = "";
        this.imageUrl = "";

        this.isLoggedIn = false;
      })
      .catch(err => console.error(err));
  }

  ngOnInit() {

  }

}
Run Code Online (Sandbox Code Playgroud)

我尝试了不同的方法,但仍然出现此错误,有人知道如何解决吗?

这是login.module.ts,我以前没有接触过这个,但是LoginPageModule在这里,所以问题是从这里开始的吗?

import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { FormsModule } from '@angular/forms';
import { Routes, RouterModule } from '@angular/router';

import { IonicModule } from '@ionic/angular';

import { LoginPage } from './login.page';

const routes: Routes = [
  {
    path: '',
    component: LoginPage
  }
];

@NgModule({
  imports: [
    CommonModule,
    FormsModule,
    IonicModule,
    RouterModule.forChild(routes)
  ],
  declarations: [LoginPage]
})
export class LoginPageModule {}
Run Code Online (Sandbox Code Playgroud)

ari*_*f08 2

由于您使用的是 Ionic 4,因此必须添加/ngx到导入目录字符串。正确的导入将是 -

登录.page.ts

import { GooglePlus } from '@ionic-native/google-plus/ngx';
Run Code Online (Sandbox Code Playgroud)

而且您还需要将 GooglePlus 添加到您的模块提供程序中,如下所示 -

登录模块.ts

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

...

@NgModule({
  imports: [
    CommonModule,
    FormsModule,
    IonicModule,
    RouterModule.forChild(routes)
  ],
  declarations: [LoginPage],
  providers: [GooglePlus]
})
export class LoginPageModule {}
Run Code Online (Sandbox Code Playgroud)