[SOLVED] Ionic2 identify back view

How could I identify in ionic2 the back/calling view?

in ioni1 I was using

var backView:ionic.View = this.$ionicHistory.backView();
backView.stateName === ‘app.view_I_want_to_test’;

I was thinking about getting the view controller, but don’t know how to test if that view controller is the view I’m interested in.

let lastView:ViewController = this.navController.getPrevious(this.navController.getActive());

Use NavController API

Could you develop your answer?

I mean of course I had a look at the API…

I forgot the details, but you could use console.log() to figure out the comparable field in a returned view controller, the name of the component is probably in it.

Thx for tips.

I found a solution which I don’t like because I’ve to do a dirty “any” cast to access a private value for the comparison but following code do the job:

onPageDidEnter() {
    // this.navController.last() strangely equals the view which entered
    let previousView:ViewController = this.navController.getPrevious(this.navController.last());
    if (previousView != null && (<any> previousView).instance instanceof MyPage) {
   } else {
1 Like