I have a MainCtrl containing a still frame for the story, for example:
$scope.urlHistory = [];
$scope.$on('$routeChangeSuccess', function () {
if ($location.$$absUrl.split('#')[1] !== $scope.urlHistory[$scope.urlHistory.length - 1]) {
$scope.urlHistory.push($location.$$absUrl.split('#')[1]);
}
});
Then in the same controller I have a GoBack () function that I would like to call when the back button is pressed,
$scope.goBack = function () {
$scope.urlHistory.pop();
$location.path($scope.urlHistory[$scope.urlHistory.length - 1]);
};
This should work because from my index.html I call it with ng-click = "goBack ()" and everything works as expected.
I use this for device events of the same controller;
function onBackKeyDown() {
alert("back");
$scope.goBack();
}
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
alert("deviceready");
document.addEventListener("backbutton", onBackKeyDown, false);
};
I see warnings, but the application does not move backward. Something happens because if I double-click the device button back, ng-click = "goBack ()" suddenly brings me back to the application start page. Am I using $ scope incorrectly? Testing this on Win Phone and Android. Using the Phonegap assembly.
edit: , $scope.goBack(); - devicelistener.