In my code, I am attempting to set up $rootScope as a global variable so that it can be accessed in the controller.
Here is an excerpt from app.js:
angular.module('app', ['ionic', 'app.controllers', 'app.routes', 'app.services', 'app.directives'])
.run(function($ionicPlatform,$rootScope) {
$ionicPlatform.ready(function() {
// Some code here...
pushNotification = window.plugins.pushNotification;
pushNotification.register(
onNotification,
errorHandler,
{
'badge': 'true',
'sound': 'true',
'alert': 'true',
'ecb': 'onNotification',
'senderID': '999999999999',
}
);
});
})
window.onNotification = function(e){
// Switch statement and logic here...
};
window.errorHandler = function(error){
// Error handling logic...
}
Although I am able to retrieve the device_token and display it in an alert, I am running into issues when trying to access it through $rootScope in the controller.
Here is some related code from Controller.js:
angular.module('app.controllers', [])
.controller('onWalletWelcomesCtrl', function($scope, $ionicModal,User,$ionicLoading,$rootScope) {
$ionicModal.fromTemplateUrl('signup-modal.html', {
id: '1',
scope: $scope,
backdropClickToClose: false,
animation: 'slide-in-up'
}).then(function(modal) {
$scope.oModal1 = modal;
});
$scope.proceed = function(){
alert($rootScope.devicetoken);
$ionicLoading.show({template: '<ion-spinner icon="android"></ion-spinner>'});
}
})
Unfortunately, I am receiving 'undefined' when trying to alert the devicetoken in the proceed function. I need guidance on how to properly utilize $rootScope within the window.onNotification function to successfully pass the devicetoken to the controller. Any suggestions on best practices for sharing variables would be greatly appreciated.