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

5
我正在尝试为我的ionic 4应用程序插入Google登录功能,但每次我点击登录按钮时都会出现问题,就像这样:have a problem like this
Cannot access 'LoginPageModule' before initialization

我的 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() {

  }

}

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

这是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 {}

点击登录按钮时执行的代码是什么?您需要展示更多的代码。 - Alexandre Khoury
实际上,当我点击登录时,它会重定向到login.page.html页面,其中放置了Google登录按钮。但是在访问login.page.html页面时,会出现“无法在初始化之前访问'LoginPageModule'”的错误。 - naoval
最近我尝试评论公共的GooglePlus:GooglePlus,我可以访问login.page.html并且错误已经消失了,但我实际上不知道为什么会发生这种情况。 - naoval
你能分享一下 login.page.module.ts 文件吗?之前它正常工作了吗? - arif08
再看一遍。 - naoval
1个回答

2

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

login.page.ts

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

同时,您需要像这样将GooglePlus添加到您的模块提供程序中 -

login.module.ts

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

...

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

但是当我使用'@ionic-native/google-plus/ngx';时,Ionic找不到该模块,因此会出现另一个错误。 - naoval
我使用以下指令 npm install @ionic-native/google-plus@5.0.0-beta.14 解决了那个错误,现在我可以在我的应用程序中使用 /ngx 了,但是现在我又遇到了新的错误 LOL。 - naoval

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接