2016-09-21 1 views
0

J'ai configuré des Pushbots pour fonctionner avec mon application PhoneGap, mais comme la configuration et l'initialisation de Pushbots ont lieu dans le fichier index.js, je ne peux pas appeler méthodes à l'intérieur de mon contrôleur angulaire principal.Notification de pushbots de poignées cliquée dans le contrôleur angularjs de l'application PhoneGap

Chaque fois que l'utilisateur clique sur une notification, je voudrais exécuter une fonction à partir de mon contrôleur principal et naviguer vers une page.

Comment puis-je y parvenir?

Voici mon fichier index.js à l'événement onDeviceReady mis en place:

function onDeviceReady() { 
    // Handle the Cordova pause and resume events 
    document.addEventListener('pause', onPause.bind(this), false); 
    document.addEventListener('resume', onResume.bind(this), false); 

    // TODO: Cordova has been loaded. Perform any initialization that requires Cordova here. 
    document.addEventListener("backbutton", onBackKeyDown, false); 

    window.plugins.PushbotsPlugin.initialize(.....); 
    window.plugins.PushbotsPlugin.on("registered", function(token){ 
     console.log("Registration Id:" + token); 
    }); 

    window.plugins.PushbotsPlugin.getRegistrationId(function(token){ 
     console.log("Registration Id:" + token); 
    }); 

    window.plugins.PushbotsPlugin.on("notification:received", function(data){ 
     console.log("received:" + JSON.stringify(data)); 
    }); 

    // Should be called once the notification is clicked 
    window.plugins.PushbotsPlugin.on("notification:clicked", function(data){ 
     $scope.LoadMyPage(); //this is not getting fired... 
     alert("clicked:" + JSON.stringify(data)); 
     console.log("clicked:" + JSON.stringify(data)); 
    }); 
}; 
+0

onDeviceReady est à l'intérieur contrôleur? – vbharath

Répondre

1

Vous pouvez utiliser émettre $ sur la portée lorsque la notification est cliqué.

window.plugins.PushbotsPlugin.on("notification:clicked", function(data){ 
    console.log("clicked:" + JSON.stringify(data)); 
    $rootScope.$emit('onNotificationClick'); 
}); 

gérer cet événement en principal à l'aide

$rootScope.$on('onNotificationClick', function() { 
// write your logic here 
}) 

Hope this helps