About tab and modal


I have an app, with several tabs, and for one of the tabs, user need to login. I use the ‘$stateChangeStart’ to check whether he/she has login, if not, open a login modal. like this:

    $rootScope.$on('$stateChangeStart', function (event, toState, toParams, fromState, fromParams) {
    if (('data' in toState) && ('access' in toState.data)) {
        if (!Auth.isLoggedIn()) {
            $log.log('Not log in');

But user also has option to cancel login, and go back to the previous tabs which are open to view.

My problem is, when I click ‘cancelLogin’, the login modal is closed, but the current selected tab is the clicked tab which need authority. I want to go back the previous tab, not the clicked tab.

In the code above, I use event.preventDefault, but it seems that it prevent the tab content to display, but didn’t prevent the tab to be selected.



I tried some solution myself before I asked, but I should go over the document carefully. In ion-tab, there is a attribute ‘ng-click’, it will be trigger for clicking, I use ng-click="$state.go('tab.account')" for the tab, then the stateChangeStart will be triggered before the tab is selected.

Hope this will help.

Odd issue with $stage.go, $stateChangeStart, and tab navigation