No ion / cord event

I try to control the menu button on Android (4.4.2 - Samsung S3), but the Ionic event (and not the Cordoba base event ) does not fire:

$ionicPlatform.on("menubutton", function () { // do our stuff here (never gets called) }); 

Could anyone do this work? The launch of Ionic platform 1.0.0 and all other events fire as expected.

+6
source share
2 answers

Try the following: in .run ()

 $ionicPlatform.ready(function() { //... if (window.cordova) { $cordovaSplashscreen.hide(); document.addEventListener("menubutton", myApp.onHardwareMenuKeyDown, false); } /... 

Then in the controller:

  $scope.onHardwareMenuKeyDown = function() { alert('menu button is working'); } 

Another way to do something:

 angular.module('myApp', ['ngCordova', 'ionic', 'myApp.controllers']) .run(function($ionicPlatform, $rootScope, $state, $localstorage,$ionicSideMenuDelegate ) { $ionicPlatform.ready(function() { document.addEventListener("menubutton", onMenuKeyDown, false); function onMenuKeyDown() { console.log("some menu pops pup!! "); // here change the view , etc... $rootScope.$apply(); } }); }) 
+2
source

There is no line in the documents.

 document.addEventListener("deviceready", function() { ... navigator.app.overrideButton("menubutton", true); // <-- Add this line document.addEventListener("menubutton", yourCallbackFunction, false); ... }, false); 

https://issues.apache.org/jira/browse/CB-9949#comment-14989073

+2
source

Source: https://habr.com/ru/post/988951/


All Articles