ANISUNDAR
ANISUNDAR

Reputation: 807

ionic using get previous page name

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

Upvotes: 8

Views: 11800

Answers (3)

kunal shaktawat
kunal shaktawat

Reputation: 1520

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

this.navCtrl.getPrevious().name;

or

this.nav.getPrevious().name;

Upvotes: 1

Bashar Altakrouri
Bashar Altakrouri

Reputation: 10595

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);
}

Upvotes: 2

Chaitanya Mankala
Chaitanya Mankala

Reputation: 1704

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);
    }
}

Upvotes: 12

Related Questions