Issue
I want to create a UI in the Ionic Framework sort of Android Fragments.
The header will have buttons etc which have animations. That's why I cannot use navctrl.push or navctrl.setroot. I need to change only the content of ion-content (MainPage) and load a new Page which contains only ion-content.
Below is a picture that presents how I would like to do it.
Are there any possibilities to do it?

app.html
<ion-header>
<ion-navbar>
<ion-title>Blabla</ion-title>
<button ion-button color="primary" (click)="home()">Home</button>
<button ion-button color="primary" (click)="second()">Second</button>
</ion-navbar>
</ion-header>
<ion-content>
</ion-content>
<ion-nav #myNav [root]="rootPage"></ion-nav>
app.component.ts
import { Component, ViewChild } from '@angular/core';
import { Platform, NavController } from 'ionic-angular';
import { StatusBar } from '@ionic-native/status-bar';
import { SplashScreen } from '@ionic-native/splash-screen';
import { HomePage } from '../pages/home/home';
import { SecondpagePage } from '../pages/secondpage/secondpage';
@Component({
templateUrl: 'app.html'
})
export class MyApp {
@ViewChild('myNav') nav: NavController;
rootPage:any = HomePage;
constructor(platform: Platform, statusBar: StatusBar, splashScreen: SplashScreen) {
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();
});
}
home() {
this.nav.setRoot(HomePage);
}
second() {
this.nav.setRoot(SecondpagePage);
}
}
In HomePage and SecondPage I put only <ion-content>Test1</ion-content> and <ion-content>Test2</ion-content>.
Now I have that situation - the header "covers" the rest. So I don't see any text because it's below the header. How can I change that behavior?
Solution
Sure. You can have named NavControllers
app.component.ts
import {MainPage} from 'main'
@Component({
template: '<ion-nav [root]="rootPage"></ion-nav>'
})
class MyApp {
// First page to push onto the stack
rootPage = MainPage;
}
main.component.ts
import { Component, ViewChild } from '@angular/core';
import { NavController } from 'ionic-angular';
@Component({
template: `
<ion-header>{{ YOUR HEADER }}</ion-header>
<ion-content>
<ion-nav #yourNav [root]="rootPage"></ion-nav>
</ion-content>
`
})
export class MainPage {
@ViewChild('yourNav') nav: NavController
public rootPage: any = StartPage;
public goSomeWhere() {
this.nav.push(SomeWhere);
}
public goSomeWhereElse() {
this.nav.push(SomeWhereElse);
}
}
Answered By - Valentin Klinghammer
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.