ionic using get previous page name

半世苍凉 提交于 2020-01-23 05:57:55

问题


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


回答1:


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



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



回答3:


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

this.navCtrl.getPrevious().name;

or

this.nav.getPrevious().name;



来源:https://stackoverflow.com/questions/44544646/ionic-using-get-previous-page-name

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!