Ionic - View Leave Events Never Called

后端 未结 4 622
旧巷少年郎
旧巷少年郎 2021-01-19 00:41

After updating an existing Ionic project from 1.13-beta to 1.14-beta I\'ve experienced some behaviour I can\'t explain. When changing from one viewstate to another, the old

4条回答
  •  耶瑟儿~
    2021-01-19 01:11

    This is an open issue https://github.com/driftyco/ionic/issues/2869 and probably occurs when view-cache="false".

    On my case $ionicView.leave worked in nested views but not when moving between tabs nor did $ionicParentView.leave so I came around it with another solution.

    Solution: On MAIN controller I added:

    $rootScope.$on('$stateChangeStart', function(event, toState, toParams, fromState, fromParams) {
         if (fromState.name === 'name-of-leaving-state') {
    
          //your code here, similar behavior with .$on('$ionicView.leave') 
    
         }
    });
    

    Hope it helps

提交回复
热议问题