This is a very simple question but i’m to noob to figure out alone the solution, i googled and looked for explanations but i really think i need someone specifically helping me out on this one
I just implemented a side-menu and i added this code in app.html:
Usually i’d write my method in the page specific .ts file but now i have my html code inside app.html which is structured differently and hasn’t an app.ts file. I just want to access and use the openPage() and maybe even more resources and stuff.
Thank you so much for that, sooo useful. I have no idea how your menu works and your code is incomprehensible for me sadly but i managed to understand how to use methods inside my app.html.
I imported two new components inside my app.component.ts: Nav and ViewChild
import { Component, ViewChild } from '@angular/core';
import { Platform, Nav } from 'ionic-angular';ar';
Added this weird @ViewChild(Nav) line of code that i have zero clue what it does/means:
I may be missing something here;) but do you have app.component.ts file close to your template (app.html)?
You need to use that and you need no ViewChild bindings to do that.
in your app.component.ts (after imports and decorators):
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();
});
}
Hey @Fieel I feel like your answer is a confusion and not a solution. It works simply cause you are using ViewChild to be able to “call” to Nav from your typescript. But from the original post it seems like all you need is to place method into app.component.ts
I couldn’t inject my navcontroller in the constructor without errors so the only way to access a nav item and implement the ‘page pushing’ in the method i need is that one as far as i understood.
How am i supposed to call the nav methods if i don’t have a navController or Nav object?
This is what i did at first:
import { NavController } from 'ionic-angular';
export class MyApp {
rootPage:any = TabsPage;
constructor(platform: Platform,
statusBar: StatusBar,
splashScreen: SplashScreen,
public navCtrl: NavController) {
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();
});
}
public openHomePage() {
this.navCtrl.setRoot(TabsPage);
}
I think this is a great attitude. Also, I think Ionic programming is hard, because to do it well, you have to know a lot of other things. So the more tools you can put in your toolbox, the better. Incidentally, when I was learning Ionic, I bought the Angular book by fullstack.io, which was extremely helpful.