$rootScope.$on('$stateChangeSuccess', function (ev, to, toParams, from, fromParams) {
//assign the "from" or "to" parameter to something
console.log(from)
});
Pretty much you can see to.name as the page you are going to; and from.name as the state you are coming from.
if (from.name == "app.view2" && to.name =="app.view1"){
// do something when you go from state app.view2 to state app.view1
}
Full code:
$rootScope.$on('$stateChangeSuccess', function (ev, to, toParams, from, fromParams) {
if (from.name == "app.view2" && to.name =="app.view1"){
//do something
}
});