How can i get the $scope or a instance of controller on resume method? It is possible?
I need make a refresh data inside a controller after on resume!
document.addEventListener(“resume”, onResume, false);
function onResume() { /* code */ }
How can i get the $scope or a instance of controller on resume method? It is possible?
I need make a refresh data inside a controller after on resume!
document.addEventListener(“resume”, onResume, false);
function onResume() { /* code */ }
Right now we don’t have a method that deals with this, but it doesn’t mean its not possible. If your willing to write some stuff, you can make a custom wrapper to deal with this event.
This way, things can be scoped correctly.
You could also add an event listener in app run method and broadcast an event that you can catch in your specific controller
app.module(‘myApp’,[…]).run(function($rootScope){
window.addEventListener(“resume”, function () {
$rootScope.$broadcast(appEvents.resume);
});
});
Thanks for the replies.
My solution was:
// Resume refresh
$rootScope.$on('onResumeCordova', function(event) {
$scope.refreshList();
});
// System events
document.addEventListener("resume", resume, false);
function resume() {
var div = document.getElementsByTagName('body')[0];
var scope = angular.element(div).scope();
var rootScope = scope.$root;
rootScope.$apply(function() {
rootScope.$broadcast('onResumeCordova');
});
}
I used document.addEventListener
instead of window.addEventListener
cause the window.addEventListener
doesn’t work 。
There is a very simple way to to this in ionicframework. Simple inject $ionicPlatform and use on method to listen to the default cordova events like resume
$ionicPlatform.on('resume', function(){ //rock on });
I tried this:
$ionicPlatform.on("resume", function(event) {
$log.info('app resume event', event);
});
but I never see any log messages when I switch to other apps and switch back…
@eno do you have the cordova device plugin (org.apache.cordova.device) installed?
Its in my list of plugins and I see it in my platforms
folders (i.e. Device.java
for Android and CDVDevice.{m,h}
for iOS.
Actually, it seems to be working now - go figure
// example.js file
// Wait for device API libraries to load
//
function onLoad() {
document.addEventListener("deviceready", onDeviceReady, false);
}
// device APIs are available
//
function onDeviceReady() {
document.addEventListener("resume", onResume, false);
}
function onResume() {
// Handle the resume event
}
https://cordova.apache.org/docs/en/latest/cordova/events/events.html