8

I am using ionic 2.

I need get 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 am getting

Current opened view is : t

How can i get previous page name.

Kindly advice me,

Thanks

ANISUNDAR
  • 787
  • 5
  • 12
  • 28

3 Answers3

12

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);
    }
}
Chaitanya Mankala
  • 1,594
  • 17
  • 24
2

In ionic +2 you can simply use:

this.navCtrl.last().name

Here is a simple example to log the name

constructor(public navCtrl:NavController){
    console.log("Previous Page is called = " + this.navCtrl.last().name);
}
Future2020
  • 9,939
  • 1
  • 37
  • 51
1

if you want a history/previous page name in ionic you can use this.

this.navCtrl.getPrevious().name;

or

this.nav.getPrevious().name;

kunal shaktawat
  • 1,428
  • 12
  • 21