Reputation:
I am having one cordova mobile app developed with the help of angularJS. In that, i have added the event listener 'resume' that calls when you log in to app, come out from the app without logout and again tap on the application icon on mobile to see it again.
My front view is this:
<!DOCTYPE html>
<html ng-app="iot">
<head>
<meta charset="utf-8">
<title>Data Cloud</title>
<meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">
<link href="css/ionic.min.css" rel="stylesheet">
<link href="css/style.css" rel="stylesheet">
<script src="js/app.js"></script>
......Application js are here.........
<script type="text/javascript">
function onLoad() {
document.addEventListener("resume", onResume, false);
}
</script>
</head>
<body onload="onLoad()" ng-controller="MainCtrl">
<script type="text/javascript">
function onResume() {
if (window.localStorage.getItem("userid") === null) {
alert('Hi');
}else{
alert('calling');
$scope.checkForUpdate();
}
}
</script>
<ion-nav-view animation="slide-left-right"></ion-nav-view>
...
My checkForUpdate();
function is in controller MainCtrl
inside the app.js
whose js file i have included in this page too.
When i open the app for the first time it is getting called and shows if alert from if
part of the function onResume()
then i logs in and come out from the app. Next time when i click on app it starts from where i left and show me alert calling
but the next part does not execute i came to know that $scope is coming undefined here where as the respective function is in my MainCtrl
controller which is in app.js file how to call that function? Any idea
Thanks in advance for response.
Upvotes: 1
Views: 127
Reputation: 909
See this blogpost how to use resume using Angular and Ionic , http://tripleneo.nl/resume-app-using-angularjs-ionic/
.run(function ($ionicPlatform, $state, $timeout) {
$ionicPlatform.ready(function () {
document.addEventListener("deviceReady", function () {
document.addEventListener("resume", function () {
$timeout(function () {
navigator.notification.confirm(
"\nYou are still tracking an activity. Do you want to view it?",
function () {},
"Information", ["YES", "NO"]
);
}, 0);
}, false);
});
});
})
Upvotes: 0