运行离子应用程序时出现此错误:
node_modules
在构造函数中调用AuthService(类型为Injectable)时。
奇怪的是,它在其他课程中的表现非常好!
LoggedinPage: (有问题)
Can't resolve all parameters for LoggedinPage: (?, [object Object], [object Object]).
联系页面: (正常工作)
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)
{
}
}
类AuthService:
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功能已被删除,因为它们很多,而且不需要进行此特定查询。
我正在使用VSCode,并且在构造函数中提到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');
}
}
);
}
}
答案 0 :(得分:2)
您遇到了循环依赖
LoggedinPage => AuthService => LoggedinPage
从import { LoggedinPage } from './../pages/loggedin/loggedin';
删除AuthService
应修复此问题。