$ionicView.enter not firing on ALL child views

If there are multiple child views on a page the $ionicView.enter and $ionicView.leave events are only fired once on one of the child views not once on ALL the child views

An extract from my code that has side menus and tabs whereby there is a parent abstract view (menuCtrl) that contains two child views, one for the main content view (mainContentCtrl) and one for the sidemenu view (rightMenuCtrl).

$stateProvider

.state('app', {
  url: '',
  abstract: true,
  views: {
    '': {
      templateUrl: 'templates/menu.html',
      controller: 'menuCtrl as menu'
    }
  }
})
.state('app.page', {
  url: '/page',
  views: {
    'rightMenuContent': {
      templateUrl: 'templates/right-menu.html',
      controller: 'rightMenuCtrl as rightMenu'
    },
    'mainContent': {
      templateUrl: 'templates/main-content.html',
      controller: 'mainContentCtrl as main'
    }
  }
})

.controller(menuCtrl’, [’$scope’, function($scope) {
$scope.$on(’$ionicView.enter’, function() { console.log (‘menu enter’); });
$scope.$on(’$ionicView.leave’, function() { console.log (‘menu leave’); });
} ])

.controller(rightMenuCtrl’, [’$scope’, function($scope) {
$scope.$on(’$ionicView.enter’, function() { console.log (‘right menu enter’); });
$scope.$on(’$ionicView.leave’, function() { console.log (‘right menu leave’); });
} ])

.controller(mainContentCtrl’, [’$scope’, function($scope) {
$scope.$on(’$ionicView.enter’, function() { console.log (‘main content enter’); });
$scope.$on(’$ionicView.leave’, function() { console.log (‘main content leave’); });
} ])

When FIRST displaying the views the menuCtrl view enter event is fired and only the mainContentCtrl view enter event is fired.
When FIRST leaving the page menuCtrl view leave event is fired and only the mainContentCtrl view leave event is fired.

When entering the page for the SECOND or more time the menuCtrl view enter event is fired and this time the rightMenuCtrl view enter event is fired.
When leaving the page for the SECOND or more time the menuCtrl view leave event is fired and this time the mainContentCtrl view enter event is fired.

Therefore even though the parent view has two child views the enter and leave events are only fired on one of the child views and even stranger when retrieving from cache the enter and leave events are fired on the opposing child views.

1 Like