1. 新增tab頁面
下完指令後可以看到終端機的訊息如下
產生了一個tab4的資料夾
1.1. 修改路由
在crm\src\app\tabs\tabs-routing.module.ts
加上tab4
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
| import { NgModule } from '@angular/core'; import { RouterModule, Routes } from '@angular/router'; import { TabsPage } from './tabs.page';
const routes: Routes = [ { path: 'tabs', component: TabsPage, children: [ { path: 'tab1', loadChildren: () => import('../tab1/tab1.module').then(m => m.Tab1PageModule) }, { path: 'tab2', loadChildren: () => import('../tab2/tab2.module').then(m => m.Tab2PageModule) }, { path: 'tab3', loadChildren: () => import('../tab3/tab3.module').then(m => m.Tab3PageModule) }, { path: 'tab4', loadChildren: () => import('../tab4/tab4.module').then(m => m.Tab4PageModule) }, { path: '', redirectTo: '/tabs/tab1', pathMatch: 'full' } ] }, { path: '', redirectTo: '/tabs/tab1', pathMatch: 'full' } ];
@NgModule({ imports: [RouterModule.forChild(routes)], }) export class TabsPageRoutingModule {}
|
1.2. 修改頁面
crm\src\app\tabs\tabs.page.html
加上tab4
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
| <ion-tabs>
<ion-tab-bar slot="bottom"> <ion-tab-button tab="tab1"> <ion-icon name="triangle"></ion-icon> <ion-label>Tab 1</ion-label> </ion-tab-button>
<ion-tab-button tab="tab2"> <ion-icon name="ellipse"></ion-icon> <ion-label>Tab 2</ion-label> </ion-tab-button>
<ion-tab-button tab="tab3"> <ion-icon name="square"></ion-icon> <ion-label>Tab 3</ion-label> </ion-tab-button> <ion-tab-button tab="tab4"> <ion-icon name="square"></ion-icon> <ion-label>Tab 4</ion-label> </ion-tab-button> </ion-tab-bar>
</ion-tabs>
|
crm\src\app\app-routing.module.ts
可以移除剛剛自動產生的 tab4 path
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
| import { NgModule } from '@angular/core'; import { PreloadAllModules, RouterModule, Routes } from '@angular/router';
const routes: Routes = [ { path: '', loadChildren: () => import('./tabs/tabs.module').then(m => m.TabsPageModule) }, { path: 'tab4', loadChildren: () => import('./tab4/tab4.module').then( m => m.Tab4PageModule) } ]; @NgModule({ imports: [ RouterModule.forRoot(routes, { preloadingStrategy: PreloadAllModules }) ], exports: [RouterModule] }) export class AppRoutingModule {}
|
2. 新增news頁面
動手玩一些實驗
2.1. 建立假數據
crm\src\app\news\news.page.ts
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
| import { Component, OnInit } from '@angular/core';
@Component({ selector: 'app-news', templateUrl: './news.page.html', styleUrls: ['./news.page.scss'], }) export class NewsPage implements OnInit {
constructor() { } public list:any=[]; ngOnInit() { for(let i=0; i <10;i++) { this.list.push(`這是第${i}條數據`); } }
}
|
2.2. 讀取數據和加入返回鍵
crm\src\app\news\news.page.html
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
| <ion-header> <ion-toolbar> <ion-buttons slot="start"> <ion-back-button></ion-back-button> </ion-buttons> <ion-title>news</ion-title> </ion-toolbar> </ion-header>
<ion-content> <ion-list> <ion-item *ngFor="let item of list"> <ion-label>{{item}}</ion-label> </ion-item> </ion-list> </ion-content>
|
2.3. 在頁籤4上加入按鍵導向到news頁面
crm\src\app\tab4\tab4.page.html
1 2 3 4 5 6 7 8 9 10 11 12 13 14
| <ion-header> <ion-toolbar> <ion-title>tab4</ion-title> </ion-toolbar> </ion-header>
<ion-content> <ion-button shape="round" color="primary" [routerLink]="['/news']"> Click me </ion-button> </ion-content>
|
2.4. 結果截圖-頁籤4
2.5. 結果截圖-news頁
3. 學習資源
Ionic4 Ionic5视频教程_Ionic4.x Ionic5.x入门实战教程