How to detect page change in ionic

Suppose I am in page ‘A’ and moving to page ‘B’, then how do I detect that page is being changed?

It was something like this in jquery-mobile:

$(document).on("pagehide",function(){
});

How do I do the same using Ionic?

$rootScope.$on('$stateChangeStart',function(event, toState, toParams, fromState, fromParams){
        ...
    });