Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ionic using get previous page name

Tags:

ionic2

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

like image 672
ANISUNDAR Avatar asked Jun 14 '17 12:06

ANISUNDAR


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);
    }
}
like image 137
Chaitanya Mankala Avatar answered Jan 03 '23 19:01

Chaitanya Mankala


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);
}
like image 35
Future2020 Avatar answered Jan 03 '23 19:01

Future2020


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

this.navCtrl.getPrevious().name;

or

this.nav.getPrevious().name;

like image 30
kunal shaktawat Avatar answered Jan 03 '23 21:01

kunal shaktawat