I wish to handle the hardware back button for that i need to get the name of the current view.
I am using the tabs template and trying to get the current tab name doing the following
Not a solution, just a remark. I “often” see posts on the forum referencing the error “returns t” and also often see that the solutions were somewhere in missing injections or that errors were still displayed during the build process…if that could help
@almighty99 about handling the back button, here’s what I do:
@reedrichards Thanks for the reply. I did double check. No error during the build process and the strange thing is that getting the active component works perfectly in the browser. And it works in the device to but returns t in place of the component name
I don’t think it is a good idea to rely on class names in JavaScript, ever. What is probably happening is that a minifier/uglifier is changing the names out from under you.
@reedrichards@rapropos
Yes the t is a result of the minification hence it only shows up when built for device.
Can you guys clarify one thing here.
Where to register backbutton handler so that it will effect the entire app? I am using the Tabs template and I tried registering it in the tabs.ts file but it didn’t work, as there was no instance of the “view” yet.
I do the register in a view accessed from a tab. It only affect that view because I call in ionViewWillLeave the function this.unregisterCustomBackActionFunction
In that case, MyPage is the active view, the view where I want to have a special back action (I built a wizard in that page, that’s why on back I’ve to go to the previous step of the wizard till I reach the first)
Figured out how to get the name of the page. This will get the title of the page.
So whatever you have in tag will show up, even the spaces and line retuns
The bad thing, IMO, about using instance-property is that it is ViewController’s private property. So there might be a risk of it disappearing/being renamed without a notice (apart from a line in release notes).
Nevertheless, I was bitten by this t-name thingy as well, and I am now refactoring my code base to use this.navCtrl.getActive().instance instanceof -style.
That’s a good point. I think in most situations there should be a way to write things that bypasses this issue entirely, such as registering custom listeners only when a particular page is active (set up in ionViewWillEnter and tear down in ionViewWillLeave).