我已经设置了Pushbots以使用我的PhoneGap应用程序,但由于pushbots的设置和启动发生在index.js文件中,我无法调用我的主angularjs控制器中的任何方法。
每当用户点击通知时,我都希望从我的主控制器运行一个功能并导航到一个页面。
我怎样才能做到这一点?
这是我的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 :(得分:1)
单击通知时,您可以在范围上使用$ emit。
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
})
希望这有帮助