got an error "Can't resolve all parameters for HomePage: ([object Object], ?, [object Object], [object Object])" . I am trying to reach my database with angularfire - users email on toastcontroller messeges when they login. Function name : "IonViewWillLoad()"
All project : https://github.com/AndriusdevLa/test
Thats my HomePage :
import { Component } from '@angular/core';
import { NavController, ModalController } from 'ionic-angular';
import { DetailPage } from '../detail/detail';
import { ToastController } from 'toast-controller';
import { AngularFireAuth } from "angularfire2/auth";
import { User } from '../../app/modals/user';
@Component({
selector: 'page-home',
templateUrl: 'home.html'
})
export class HomePage {
//public shouldReorder = false;
user = {} as User;
constructor(private aFAuth: AngularFireAuth,
private toastCtrl = ToastController,
public navCtrl: NavController,
public modalCtrl: ModalController)
{
//this.service.getPeople().subscribe( data => {
// this.people = data.results
// });
}
ionViewWillLoad(){
this.aFAuth.authState.subscribe(data => {
if(data.email && data.uid) {
let toast = this.toastCtrl.create({
message: 'User was added successfully',
duration: 3000,
position: 'top'
});
toast.onDidDismiss(() => {
console.log('Dismissed toast');
});
toast.present();
}
else {
let toast = this.toastCtrl.create({
message: 'User not found',
duration: 3000,
position: 'top'
});
toast.present();
}
});
}
}
I dont understand what is that error about, maby someone could tell me ? There are no more errors in IDE, only this one in browser (ionic serve).
App.module.ts :
import { BrowserModule } from '@angular/platform-browser';
import { HttpClient, HttpClientModule } from "@angular/common/http";
import { ErrorHandler, NgModule } from '@angular/core';
import { IonicApp, IonicErrorHandler, IonicModule } from 'ionic-angular';
import { SplashScreen } from '@ionic-native/splash-screen';
import { StatusBar } from '@ionic-native/status-bar';
import { MyApp } from './app.component';
import { HomePage } from '../pages/home/home';
import { DetailPage } from '../pages/detail/detail';
import { StartPage } from '../pages/start/start';
import { AngularFireModule } from "angularfire2";
import { FIREBASE_CONFIG } from "./app.firebase.config";
import { LoginPage } from "../pages/login/login";
import { AngularFireAuthModule } from "angularfire2/auth";
@NgModule({
declarations: [
MyApp,
StartPage,
HomePage,
DetailPage,
LoginPage,
],
imports: [
BrowserModule,
HttpClientModule,
IonicModule.forRoot(MyApp),
AngularFireModule.initializeApp(FIREBASE_CONFIG),
AngularFireAuthModule
],
bootstrap: [IonicApp],
entryComponents: [
MyApp,
StartPage,
HomePage,
DetailPage,
LoginPage,
],
providers: [
HttpClient,
StatusBar,
SplashScreen,
{provide: ErrorHandler, useClass: IonicErrorHandler},
]
})
export class AppModule {}
User.ts :
export interface User {
email: string;
password: string;
}
Edit :
When I deleted - public navCtrl: NavController, from my constructor (it wasnt used, the error became smaller, but a little bit different = ?) :
Can't resolve all parameters for HomePage: ([object Object], ?, [object Object])
The error is because angular can't access all the parameters required for the HomePage
. In your constructor, you've declared four parameters angular cannot access everything except that ToastController
. That is why the parameter in your error message is a question mark.
You have to import ToastController
properly from ionic-angular
, right now you are importing it from 'toast-controller'
unless you have something in that location you need to remove the line
import { ToastController } from 'toast-controller';
Then import ToastController properly from ionic-angular library.like this (change second line of your code)
import { NavController, ModalController, ToastController } from 'ionic-angular';
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With