ionic-framework icon indicating copy to clipboard operation
ionic-framework copied to clipboard

navCtrl.getActive().component.name returns "t" in RC0

Open prantikv opened this issue 10 years ago • 14 comments

Getting the component name or using various methods give the letter t in return. This has been seen in the Tabs template. Note that this only happens on the device. It works fine in the browser.

    console.log(this.navCtrl.getActive().component.name);
    console.log(nav.getActive().component.name);
    console.log(this.tabRef.viewCtrl);

What behavior are you expecting?

Name of the component or view is expected

Steps to reproduce:

  1. Create a tabs project.
  2. Add a button to log the current component name
  3. Build for android and run on device or emulator

Which Ionic Version? 1.x or 2.x Ionic 2 RC0

prantikv avatar Oct 05 '16 15:10 prantikv

Hello, thanks for using Ionic! This is actually expected due to our AoT compiling that happens when doing a prod build. Ionic does a prod build when doing ionic run android/ios, ionic emulate android/ios or ionic build android/ios. All of the methods will still work the same as the name, which is t in this case, still refers to the same component.

jgw96 avatar Oct 07 '16 16:10 jgw96

Hi @jgw96 ,

What I should do to get the name property, instead of t, or e, or r property?

omgalbert avatar Apr 04 '17 10:04 omgalbert

What I should do to get the name property, instead of t, or e, or r property?

gulullu avatar Apr 28 '17 05:04 gulullu

+1

derasmus avatar May 05 '17 11:05 derasmus

We can get component-name with "this.nav.getActive().id" in AoT. not use "name".

rdlabo avatar Jul 13 '17 14:07 rdlabo

its working "this.nav.getActive().id" in AoT. thanks

chandumunna avatar Jul 29 '17 06:07 chandumunna

This doesn't seem to work as of currently (ionic CLI 3.18.0, ionic-angular 3.7.1). "this.nav.getActive().id" returns a shortened string like "tn-4", not the original component name. I'm using this method in production to send telemetry about view navigation, so the original component name is what I'm looking for. Is there any other way to obtain it?

bedej avatar Nov 17 '17 00:11 bedej

+1

ThalesMatoso avatar Dec 07 '17 21:12 ThalesMatoso

We are also seeing this issue as it is actually reporting the name as blank when running ionic cordova run browser --prod. With the name being reported as mentioned before without the --prod

rphovley avatar Jan 27 '18 02:01 rphovley

+1

xyboox avatar Apr 10 '18 19:04 xyboox

+1 Could be very useful to have component name also in "ionic build --prod"!

matteobattista avatar Apr 18 '18 15:04 matteobattista

+1 plz....

alaordev avatar Apr 19 '18 02:04 alaordev

If you need name just to compare with specific page / component, you can copare active component with that component directly: let activeView = this.navCtrl.getActive(); if (activeView.component == ConversationPage) { } as ruben0909 mentioned here. It helped me a lot.

GREPY avatar Apr 26 '18 07:04 GREPY

Thanks for the issue! This issue is being locked to prevent comments that are not relevant to the original issue. If this is still an issue with the latest version of Ionic, please create a new issue and ensure the template is fully filled out.

ionitron-bot[bot] avatar Sep 01 '18 05:09 ionitron-bot[bot]