我遇到了保存数据的问题。它说
运行时错误:未捕获(在承诺中):导航堆栈至少需要一个根页
这是我的app.component.ts
import { Component, ViewChild } from '@angular/core';
import { Platform, NavController, MenuController } from 'ionic-angular';
import { StatusBar } from '@ionic-native/status-bar';
import { SplashScreen } from '@ionic-native/splash-screen';
import firebase from 'firebase';
//import { SearchPage } from '../pages/search/search';
import { AppointmentPage } from '../pages/appointment/appointment';
import { TabsPage } from '../pages/tabs/tabs';
import { AuthServices } from '../provider/auth.service';
import { LoginPage } from '../pages/login/login';
import { SignUpPage } from '../pages/sign-up/sign-up';
@Component({
templateUrl: 'app.html'
})
export class MyApp {
rootPage:any = TabsPage;
AppointmentPage: AppointmentPage;
LoginPage =LoginPage;
SignUpPage = SignUpPage;
isAuthenticated = false;
@ViewChild('nav') nav: NavController;
constructor(platform: Platform, statusBar: StatusBar, splashScreen: SplashScreen,
private authService: AuthServices,
private menuCtrl: MenuController,) {
firebase.initializeApp({
apiKey: "AIzaSyCearIrLYBjHJCq46MOXAlw-fnmm5loS6U",
authDomain: "mydatalogin-3ed97.firebaseapp.com",
});
firebase.auth().onAuthStateChanged(user => {
if (user){
this.isAuthenticated = true;
this.nav.setRoot(this.rootPage);
}
else{
this.isAuthenticated = false;
this.nav.setRoot(this.LoginPage);
}
});
platform.ready().then(() => {
// Okay, so the platform is ready and our plugins are available.
// Here you can do any higher level native things you might need.
statusBar.styleDefault();
splashScreen.hide();
});
}
onLoad(page: any){
this.nav.setRoot(page);
this.menuCtrl.close();
}
onLogout(){
this.authService.onLogout();
this.menuCtrl.close();
}
}
这是form.ts
import { Component } from '@angular/core';
import { NavController, ViewController } from 'ionic-angular';
@Component({
selector: 'page-appointment',
templateUrl: 'appointment.html',
})
export class AppointmentPage {
fname: string;
pno: string;
today: Date;
time: string;
boutique: string;
planner: string;
halls: string;
catering: string;
services: string;
message: string;
constructor(public navCtrl: NavController, public view: ViewController) {
}
saveItem(){
let newItem = {
boutique: this.boutique,
planner: this.planner,
halls: this.halls,
catering: this.catering,
services: this.services,
today: this.today,
fname: this.fname,
pno: this.pno,
time: this.time,
message: this.message,
}
console.log('saved item: ', newItem);
this.view.dismiss(newItem);
}
}
我尝试刷新所有文件和浏览器,但它仍然无法保存数据。我只使用firebase登录和保存我使用离子存储的数据..