【问题标题】:Ionic 2 rootPage not showingIonic 2 rootPage 未显示
【发布时间】:2017-02-22 22:24:12
【问题描述】:

我是 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 {}

如果您还有其他需要查看的文件,请说出来,我会添加它们。 谢谢你的到来。

【问题讨论】:

  • 你在哪里设置标签页,你可以添加组件吗?
  • 我没有设置标签页,我现在只使用登录页
  • 浏览器控制台是否出现错误?
  • 不,我尝试先在空白应用程序上运行该页面,效果很好
  • html 还是 ts 文件?但我只想显示没有标签的登录页面。

标签: tabs ionic2


【解决方案1】:

尝试使用 ionic 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();
    });
  }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-10-27
    • 1970-01-01
    • 2018-06-11
    • 2017-03-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-03
    相关资源
    最近更新 更多