基类:
import { LoginPage } from './../login/login/login';
import { AccountData } from './../../storages/account_data';
import { Component, Injectable } from '@angular/core';
import { NavController, NavParams, Platform, ViewController } from 'ionic-angular';
/*
Generated class for the Base page.
See http://ionicframework.com/docs/v2/components/#navigation for more info on
Ionic pages and navigation.
*/
@Component({
selector: 'page-base',
templateUrl: 'base.html'
})
export abstract class BasePage {
needLogin = false;
constructor(protected accountData: AccountData, protected nav: NavController) { }
push(page: any) {
this.accountData.hasLoggedIn().subscribe(hasLoggedIn => {
if (hasLoggedIn) {
this.nav.push(page);
} else {
if (page.needLogin) {
this.nav.push(LoginPage);
} else {
this.nav.push(page)
}
}
});
}
pop() {
this.nav.pop();
}
setRoot(page: any) {
this.nav.setRoot(page);
}
}
继承该基类的:
import { AccountData } from './../../storages/account_data';
import { BasePage } from './../base/base';
import { Component } from '@angular/core';
import { NavController, NavParams } from 'ionic-angular';
/*
Generated class for the Discover page.
See http://ionicframework.com/docs/v2/components/#navigation for more info on
Ionic pages and navigation.
*/
@Component({
selector: 'page-discover',
templateUrl: 'discover.html'
})
export class DiscoverPage extends BasePage {
constructor(protected accountData: AccountData, protected navCtrl: NavController, ) {
super(accountData, navCtrl);
}
}
运行ionic serve
后报错:
Uncaught TypeError: Object prototype may only be an Object or null: undefined at setPrototypeOf ()
但是如果父类的构造方法为空的话一切正常,求解。
1
bgies 2017-03-03 14:16:23 +08:00
Change your constuctor to public or private... what happens?
constructor(public accountData: AccountData, public navCtrl: NavController, ) { super(accountData, navCtrl); } |