空白项目中的Ionic 4简单选项卡 [英] Ionic 4 simple tab in blank project

查看:232
本文介绍了空白项目中的Ionic 4简单选项卡的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经用ionic start myApp blank

现在我需要在项目中添加选项卡,我在页面中创建了文件夹选项卡,并在选项卡中创建了两个文件tabs.html tabs.ts 在tabs.html

Now i need to add tab in to the project i have create folder tabs in pages and create two file inside tabs tabs.html tabs.ts in tabs.html

<ion-tabs>
  <ion-tab [root]="homePage" tabTitle="Home" tabIcon="bulb" ></ion-tab>
  <ion-tab [root]="reclamationsPage" tabTitle="Reclamations" tabIcon="settings"></ion-tab>
</ion-tabs>

在tabs.ts

import { Component } from '@angular/core';
import { ReclamationsPage } from '../reclamations/reclamations';
import { HomePage } from '../home/home';


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

  reclamationsPage: ReclamationsPage;
  homePage: HomePage;
}

在app.module.ts中 我已添加

in app.module.ts i have add

declarations: [
    MyApp,
    HomePage,
    LoginPage,
    ReclamationsPage,
    TabsPage
  ],
  imports: [
    BrowserModule,
    HttpModule,
    HttpClientModule,
    IonicModule.forRoot(MyApp)
  ],
  bootstrap: [IonicApp],
  entryComponents: [
    MyApp,
    HomePage,
    LoginPage,
    ReclamationsPage,
    TabsPage
  ],

和app.component.ts中,我将rootPage:any更改为rootPage:any = TabsPage;

and in app.component.ts i have change rootPage:any with rootPage:any = TabsPage;

但是当我执行我的代码服务时,我已经注意到屏幕空白页中的图像

but when i excute my code ionic serve i have noting in screen blank page look the image

离子信息

Ionic:

   ionic (Ionic CLI)  : 4.2.1 (C:\Users\android\AppData\Roaming\npm\node_modules\ionic)
   Ionic Framework    : ionic-angular 3.9.2
   @ionic/app-scripts : 3.2.0

Cordova:

   cordova (Cordova CLI) : 8.1.2 (cordova-lib@8.1.1)
   Cordova Platforms     : android 7.1.1
   Cordova Plugins       : cordova-plugin-ionic-keyboard 2.1.3, cordova-plugin-ionic-webview 2.2.0, (and 8 other plugins)

System:

   Android SDK Tools : 26.1.1 (C:\Users\android\AppData\Local\Android\sdk)
   NodeJS            : v8.12.0 (C:\Program Files\nodejs\node.exe)
   npm               : 6.4.1
   OS                : Windows 10

推荐答案

tabs.html;

tabs.html;

<ion-tabs [selectedIndex]="myIndex">
    <ion-tab [root]="tab1Root" tabIcon="star"></ion-tab>
    <ion-tab [root]="tab2Root" tabIcon="home"></ion-tab>
</ion-tabs>

tabs.ts

tabs.ts

import { IonicPage, NavController, NavParams } from 'ionic-angular';

@IonicPage()
@Component({
  selector: 'page-tabs',
  templateUrl: 'tabs.html',
})

export class TabsPage{
    tab1Root = 'ReclamationsPage';
    tab2Root = 'HomePage';
    myIndex: number;
}

constructor(public navCtrl: NavController, public navParams: NavParams){
    this.myIndex = navParams.data.tabIndex || 0;
}

这篇关于空白项目中的Ionic 4简单选项卡的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆