gpt4 book ai didi

angular - 无法解析 LoggedinPage 的所有参数( Angular - 组件/可注入(inject))

转载 作者:太空狗 更新时间:2023-10-29 18:30:24 27 4
gpt4 key购买 nike

我在运行我的 ionic 应用程序时遇到此错误:

Can't resolve all parameters for LoggedinPage: (?, [object Object], [object Object]).

在构造函数中调用 AuthService(Injectable 类型)时。

奇怪的是它在其他类中工作得很好!

LoggedinPage: (有问题)

import { Component, ViewChild, ViewChildren, ElementRef } from '@angular/core';
import { NavController, NavParams } from 'ionic-angular';
import { Chart } from 'chart.js';
import { AuthService } from '../../core/auth.service';


@Component({
selector: 'page-loggedin',
templateUrl: 'loggedin.html',
})
export class LoggedinPage {

@ViewChild('barCanvas') barCanvas: ElementRef;

barChart: any;

constructor(public auth: AuthService, public navCtrl: NavController, public navParams: NavParams)
{
}
}

ContactPage: (工作正常)

import { Component, ViewChild, ViewChildren, ElementRef } from '@angular/core';
import { NavController } from 'ionic-angular';
import { AuthService } from '../../core/auth.service';
import { Chart } from 'chart.js';

@Component({
selector: 'page-contact',
templateUrl: 'contact.html'
})
export class ContactPage{

constructor(public navCtrl: NavController, public auth: AuthService)
{

}

}

AuthService 类:

import { LoggedinPage } from './../pages/loggedin/loggedin';
import { HomePage } from './../pages/home/home';
import { ContactPage } from './../pages/contact/contact';
import { AuthGuard } from './auth.guard';
import { Injectable } from '@angular/core';
import { Router, RouterModule } from '@angular/router';
import { LoadingController, AlertController, NavController } from 'ionic-angular';
import * as firebase from 'firebase/app';
import { AngularFireAuth } from 'angularfire2/auth';
import { AngularFirestore, AngularFirestoreDocument, AngularFirestoreCollection } from 'angularfire2/firestore';
import { Observable } from 'rxjs/Observable';
import 'rxjs/add/operator/switchMap';
import 'rxjs/add/observable/of';
import { GooglePlus } from '@ionic-native/google-plus';
import { NativeStorage } from '@ionic-native/native-storage';
import { Facebook } from '@ionic-native/facebook';

interface OliveandOil
{
olivequantity: number;
oilquantity: number;
}

interface OliveandOilYear
{
year: number;
}

interface User
{
uid: string;
email: string;
photoURL?: string;
displayName?: string;
}

@Injectable()
export class AuthService
{

user: Observable<User>;
client: any;
winobj: any = null;
FB_APP_ID: number = XXXXXXXXX;

key: number = 0;
objects = {};

constructor(private afAuth: AngularFireAuth, private nativeStorage: NativeStorage, private afs: AngularFirestore, private router: Router, public loadingCtrl: LoadingController, private googlePlus: GooglePlus, public alertCtrl: AlertController, public fb: Facebook, public navCtrl: NavController)
{
this.googleLoginSilent();

this.afAuth.authState.subscribe(user =>
{
if(user)
{
this.user = this.afAuth.authState; //this means alert('fire user logged in');
}
else
{
Observable.of(null); //this means alert('fire user logged out');
}
}
);
}
}

请注意,AuthService 函数已被删除,因为它们很多而且对于此特定查询不需要。

我正在使用 VSCode,在构造函数中提到 AuthService 时它没有显示任何“红色”或错误。

知道为什么它不能在同一个类中解析它吗?

谢谢

import { NgModule } from '@angular/core';
import { AuthService } from './auth.service';
import { AngularFireAuthModule } from 'angularfire2/auth';
import { AngularFirestoreModule } from 'angularfire2/firestore';
@NgModule({
imports: [
AngularFireAuthModule,
AngularFirestoreModule
],
providers: [AuthService]
})
export class CoreModule { }

最佳答案

你遇到了循环依赖

LoggedinPage => AuthService => LoggedinPage

AuthService 中删除 import { LoggedinPage } from './../pages/loggedin/loggedin'; 应该可以修复它。

关于angular - 无法解析 LoggedinPage 的所有参数( Angular - 组件/可注入(inject)),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47122705/

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