Ionic 2 rootPage没有显示

时间:2017-02-22 11:35:10

标签: tabs ionic2

我是Ionic的新手,刚刚开始了一个新项目。我选择了底部有3个标签的模板,但现在我想要一个新的起始页。 我创建了一个名为LoginPage的页面,但是当我尝试将TabsPage交换为LoginPage时,它只显示一个空白屏幕。 这是文件

app.component.ts

import { Component } from '@angular/core';
import { Platform } from 'ionic-angular';
import { StatusBar, Splashscreen } from 'ionic-native';
import { LoginPage } from '../pages/login/login';


@Component({
  templateUrl: 'app.html'
})
export class MyApp {
  rootPage = LoginPage;

  constructor(platform: Platform) {
    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();
    });
  }
}

login.ts

import { Component } from '@angular/core'; 
import { NavController } from 'ionic-angular';

@Component({
    selector: 'page-login',
    templateUrl: 'login.html'
})
export class LoginPage {

    constructor(public navCtrl: NavController) {

    }

}

app.module.ts

import { NgModule, ErrorHandler } from '@angular/core';
import { IonicApp, IonicModule, IonicErrorHandler } from 'ionic-angular';
import { MyApp } from './app.component';
import { SettingsPage } from '../pages/settings/settings';
import { ContactPage } from '../pages/contact/contact';
import { HomePage } from '../pages/home/home';
import { TabsPage } from '../pages/tabs/tabs';
import {LoginPage} from "../pages/login/login";

@NgModule({
  declarations: [
    MyApp,
      SettingsPage,
      ContactPage,
      HomePage,
      TabsPage,
      LoginPage
  ],
  imports: [
    IonicModule.forRoot(MyApp)
  ],
  bootstrap: [IonicApp],
  entryComponents: [
    MyApp,
      SettingsPage,
      ContactPage,
      HomePage,
      TabsPage,
      LoginPage
  ],
  providers: [{provide: ErrorHandler, useClass: IonicErrorHandler}]
})
export class AppModule {}

如果您需要查看其他文件,只需这样说,我就会添加它们。 感谢adventage。

1 个答案:

答案 0 :(得分:1)

尝试使用离子CLI添加登录页面

$ ionic g page login

然后在app.module.ts中添加页面并像您提到的那样编辑app.component.ts

import { Component } from '@angular/core';
import { Platform } from 'ionic-angular';
import { StatusBar, Splashscreen } from 'ionic-native';

import { LoginPage } from '../pages/login/login';


@Component({
  templateUrl: 'app.html'
})
export class MyApp {
  rootPage = LoginPage;

  constructor(platform: Platform) {
    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();
    });
  }
}