2016-09-21 28 views
0

我已經設置了Pushbots與我的PhoneGap應用程序一起工作,但由於Pushbots的設置和啓動發生在index.js文件中,我無法調用任何我的主要angularjs控制器內的方法。處理pushbots通知點擊在angularjs控制器中的PhoneGap應用程序

每當用戶點擊一個通知我想從我的主控制器運行一個功能,並導航到一個頁面。

我該如何做到這一點?

這是我的index.js文件,成立了onDeviceReady事件:

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是內部控制本次活動主? – vbharath

回答

1

您可以使用$單擊通知時的範圍發出。

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

手柄使用

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

希望這有助於

相關問題