Event.DefaultPrevent() cannot stop page to changed


#1

I am have to do things like when user changed any form element and trying to go back without saving form or trying to go other page from tabs so i have to ask for confirm really want to exit. i am doing this

var foo = $scope.$on('$stateChangeStart', function(event)
    {
        event.preventDefault();
        $ionicPopup.confirm({
        title: 'some title'
        }).then(function (res) 
        {
            console.log(res);
            if (res) 
            {
                $state.go('stateName')
            }
            else 
            {
                return;
            }
        });
    });

    $scope.$on('$destroy', foo)

But page cannot changed but page goes to blank. like

Thanks


#2

I would be much easier to watch for a back navigation event and prevent page/view navigation with priority 101.

###Read it here.


#3

Thanks for quick reply.

This function is called when i am navigate from tabs.?

var deregisterSecond = $ionicPlatform.registerBackButtonAction(
        function() 
        {
            alert("This is the second page")
        }, 100
    );
    $scope.$on('$destroy', deregisterSecond);