Note that there are some explanatory texts on larger screens.

plurals
  1. POAngularJS - $broadcast message to controllers generates duplicate notifications
    primarykey
    data
    text
    <p>In my AngularJs and phonegap/cordova application I listen for the back button event. I then broadcast this to certain controllers within my <em>app.js</em>:</p> <pre><code>document.addEventListener("deviceready", function(){ document.addEventListener('backbutton', function(){ $rootScope.$broadcast('backButton'); }, false); }, false); </code></pre> <p>In certain views I want to listen to this so that I can inform the user that they will be quitting the app and give them the option to continue or not.</p> <p>So there are two controls, lobby and game.</p> <p>When a user clicks back in the lobby they should see a notification telling them they will be quitting the app:</p> <pre><code>$rootScope.$on('backButton', function(event){ $window.navigator.notification.confirm( 'Are you sure you want to exit app?', // message $scope.exitApp, // callback to invoke 'APP', // title ['OK', 'Cancel'] // button labels ); </code></pre> <p>And if they hit OK they are logged out from the app and re-directed to the login screen.</p> <p>When they are in the game view they should be informed they will be quitting their game and then redirected to the lobby:</p> <pre><code>$rootScope.$on('backButton', function(event){ $window.navigator.notification.confirm( 'Are you sure you want to quit your game?', // message $scope.quitGame, // callback to invoke 'GAME', // title ['OK', 'Cancel'] // button labels ); }); </code></pre> <p>The issue I am seeing is that when I am in the game I see both notifications when I click the back button. One for the game which is correct but then an additional one for the lobby which is not needed.</p> <p>So this is not really a defect, this is how it should work but being relatively new to Angular I am not sure of best approach as broadcast seems inappropriate here.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload