gpt4 book ai didi

angular - 在初始化 ionic 4 之前无法访问 'LoginPageModule'

转载 作者:行者123 更新时间:2023-12-03 19:22:00 25 4
gpt4 key购买 nike

我正在尝试为我的 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 {}

最佳答案

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

登录页面.ts

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

而且您还需要像这样将 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 {}

关于angular - 在初始化 ionic 4 之前无法访问 'LoginPageModule',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59134905/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com