出错"无法解析HomePage的所有参数:([object Object],?,[object Object],[object Object])" 。我正在尝试使用angularfire访问我的数据库 - 当用户登录时,用户会在toastcontroller messeges上发送电子邮件。功能名称:" IonViewWillLoad()"
所有项目:https://github.com/AndriusdevLa/test
多数民众赞成我的主页:
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();
}
});
}
}
我不明白那个错误是什么,maby有人可以告诉我吗? IDE中没有错误,只有浏览器中的错误(离子服务)。
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;
}
修改:
当我删除 - public navCtrl:NavController,来自我的构造函数(它没有使用,错误变小了,但有点不同= ?):
无法解析HomePage的所有参数:([object Object],?,[object Object])
答案 0 :(得分:1)
错误是因为角度无法访问HomePage
所需的所有参数。在您的构造函数中,您已声明四个参数angular无法访问除ToastController
之外的所有内容。这就是错误消息中的参数是问号的原因。
您必须从ToastController
正确导入ionic-angular
,现在您要从'toast-controller'
导入它,除非您在该位置有某些内容需要删除该行
import { ToastController } from 'toast-controller';
然后从ionic-angular库中正确导入ToastController。就像这样(更改代码的第二行)
import { NavController, ModalController, ToastController } from 'ionic-angular';
答案 1 :(得分:0)
您指定的是 toastCtrl = ToastController
,而应该 private toastCtrl : ToastController
更改
发件人强>
constructor(private aFAuth: AngularFireAuth,
private toastCtrl = ToastController,
要强>
constructor(private aFAuth: AngularFireAuth,
private toastCtrl : ToastController,