Skip to content

Commit fef7a94

Browse files
committed
Simpler
1 parent 57cfb1e commit fef7a94

File tree

13 files changed

+176
-31
lines changed

13 files changed

+176
-31
lines changed

src/app/app.component.spec.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import { async, TestBed } from '@angular/core/testing';
22
import { IonicModule } from 'ionic-angular';
33

4+
import { StatusBar } from '@ionic-native/status-bar';
5+
import { SplashScreen } from '@ionic-native/splash-screen';
6+
47
import { MyApp } from './app.component';
58

69
describe('MyApp Component', () => {
@@ -12,6 +15,10 @@ describe('MyApp Component', () => {
1215
declarations: [MyApp],
1316
imports: [
1417
IonicModule.forRoot(MyApp)
18+
],
19+
providers: [
20+
StatusBar,
21+
SplashScreen
1522
]
1623
})
1724
}));

src/app/app.component.ts

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,45 @@
1-
import { Component } from '@angular/core';
2-
import { Platform } from 'ionic-angular';
1+
import { Component, ViewChild } from '@angular/core';
2+
import { Nav, Platform } from 'ionic-angular';
33
import { StatusBar } from '@ionic-native/status-bar';
44
import { SplashScreen } from '@ionic-native/splash-screen';
55

6-
import { HomePage } from '../pages/home/home';
6+
import { Page1 } from '../pages/page1/page1';
7+
import { Page2 } from '../pages/page2/page2';
78

89

910
@Component({
1011
templateUrl: 'app.html'
1112
})
1213
export class MyApp {
13-
rootPage = HomePage;
14+
@ViewChild(Nav) nav: Nav;
1415

15-
constructor(platform: Platform, statusBar: StatusBar, splashScreen: SplashScreen) {
16-
platform.ready().then(() => {
16+
rootPage: any = Page1;
17+
18+
pages: Array<{title: string, component: any}>;
19+
20+
constructor(public platform: Platform, public statusBar: StatusBar, public splashScreen: SplashScreen) {
21+
this.initializeApp();
22+
23+
// used for an example of ngFor and navigation
24+
this.pages = [
25+
{ title: 'Page One', component: Page1 },
26+
{ title: 'Page Two', component: Page2 }
27+
];
28+
29+
}
30+
31+
initializeApp() {
32+
this.platform.ready().then(() => {
1733
// Okay, so the platform is ready and our plugins are available.
1834
// Here you can do any higher level native things you might need.
19-
statusBar.styleDefault();
20-
splashScreen.hide();
35+
this.statusBar.styleDefault();
36+
this.splashScreen.hide();
2137
});
2238
}
39+
40+
openPage(page) {
41+
// Reset the content nav to have just this page
42+
// we wouldn't want the back button to show in this scenario
43+
this.nav.setRoot(page.component);
44+
}
2345
}

src/app/app.module.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,27 @@
11
import { NgModule, ErrorHandler } from '@angular/core';
22
import { IonicApp, IonicModule, IonicErrorHandler } from 'ionic-angular';
33
import { MyApp } from './app.component';
4-
import { HomePage } from '../pages/home/home';
4+
5+
import { Page1 } from '../pages/page1/page1';
6+
import { Page2 } from '../pages/page2/page2';
57

68
import { StatusBar } from '@ionic-native/status-bar';
79
import { SplashScreen } from '@ionic-native/splash-screen';
810

911
@NgModule({
1012
declarations: [
1113
MyApp,
12-
HomePage
14+
Page1,
15+
Page2
1316
],
1417
imports: [
1518
IonicModule.forRoot(MyApp)
1619
],
1720
bootstrap: [IonicApp],
1821
entryComponents: [
1922
MyApp,
20-
HomePage
23+
Page1,
24+
Page2
2125
],
2226
providers: [
2327
StatusBar,

src/pages/home/home.html

Lines changed: 0 additions & 14 deletions
This file was deleted.

src/pages/home/home.scss

Lines changed: 0 additions & 3 deletions
This file was deleted.

src/pages/page1/page1.html

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<ion-header>
2+
<ion-navbar>
3+
<button ion-button menuToggle>
4+
<ion-icon name="menu"></ion-icon>
5+
</button>
6+
<ion-title>Page One</ion-title>
7+
</ion-navbar>
8+
</ion-header>
9+
10+
<ion-content padding>
11+
<h3>Ionic Menu Starter</h3>
12+
13+
<p>
14+
If you get lost, the <a href="http://ionicframework.com/docs/v2">docs</a> will show you the way.
15+
</p>
16+
17+
<button ion-button secondary menuToggle>Toggle Menu</button>
18+
</ion-content>

src/pages/page1/page1.scss

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
page-page1 {
2+
3+
}

src/pages/page1/page1.spec.ts

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
2+
import { By } from '@angular/platform-browser';
3+
import { DebugElement } from '@angular/core';
4+
import { Page1 } from "./page1";
5+
import { IonicModule, NavController } from "ionic-angular/index";
6+
7+
describe('Page1', function () {
8+
let de: DebugElement;
9+
let comp: Page1;
10+
let fixture: ComponentFixture<Page1>;
11+
12+
beforeEach(async(() => {
13+
TestBed.configureTestingModule({
14+
declarations: [ Page1 ],
15+
imports: [
16+
IonicModule.forRoot(Page1)
17+
],
18+
providers: [
19+
NavController
20+
]
21+
});
22+
}));
23+
24+
beforeEach(() => {
25+
fixture = TestBed.createComponent(Page1);
26+
comp = fixture.componentInstance;
27+
de = fixture.debugElement.query(By.css('h3'));
28+
});
29+
30+
it('should create component', () => expect(comp).toBeDefined() );
31+
32+
it('should have expected <h3> text', () => {
33+
fixture.detectChanges();
34+
const h3 = de.nativeElement;
35+
expect(h3.innerText).toMatch(/ionic/i,
36+
'<h3> should say something about "Ionic"');
37+
});
38+
});
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ import { Component } from '@angular/core';
33
import { NavController } from 'ionic-angular';
44

55
@Component({
6-
selector: 'page-home',
7-
templateUrl: 'home.html'
6+
selector: 'page-page1',
7+
templateUrl: 'page1.html'
88
})
9-
export class HomePage {
9+
export class Page1 {
1010

1111
constructor(public navCtrl: NavController) {
1212

src/pages/page2/page2.html

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<ion-header>
2+
<ion-navbar>
3+
<button ion-button menuToggle>
4+
<ion-icon name="menu"></ion-icon>
5+
</button>
6+
<ion-title>Page Two</ion-title>
7+
</ion-navbar>
8+
</ion-header>
9+
10+
<ion-content>
11+
<ion-list>
12+
<button ion-item *ngFor="let item of items" (click)="itemTapped($event, item)">
13+
<ion-icon [name]="item.icon" item-left></ion-icon>
14+
{{item.title}}
15+
<div class="item-note" item-right>
16+
{{item.note}}
17+
</div>
18+
</button>
19+
</ion-list>
20+
<div *ngIf="selectedItem" padding>
21+
You navigated here from <b>{{selectedItem.title}}</b>
22+
</div>
23+
</ion-content>

0 commit comments

Comments
 (0)