Ionic use get previous page name

I am using ionic 2.

I need to get the previous page name.

here is my code.

 @ViewChild(Nav) nav:Nav
  constructor() {
    this.nav_app.viewDidEnter.subscribe(
      view => console.log("Current opened view is : " + view.name);
    )
  }

still i get

Current opened view is : t

How to get the previous page name.

I ask for advice

thank

+7
source share
3 answers

You can try

import { Component, ViewChild } from '@angular/core';
import { NavController } from 'ionic-angular';
export class MyApp {

    constructor(public navCtrl:NavController){
        var val=this.navCtrl.last();
        console.log("VAL");
        console.log(val);
    }
}
+12
source

In ionic +2 you can just use:

this.navCtrl.last().name

Here is a simple example to enter a name

constructor(public navCtrl:NavController){
    console.log("Previous Page is called = " + this.navCtrl.last().name);
}
+2
source

if you want to use the history / previous page in ionic, you can use this.

this.navCtrl.getPrevious().name;

or

this.nav.getPrevious().name;

0
source

Source: https://habr.com/ru/post/1679257/


All Articles