angularjs服务,听后退按钮

时间:2014-02-11 08:10:22

标签: cordova angularjs-service

是否有侦听设备后退按钮的angularjs服务?

我想在不同的控制器内部听设备后退按钮,这样我就可以访问控制器范围内的数据,并在按下后退按钮后使用它来操作动作。

类似CordovaService

notifierApp.service('CordovaService', function($document, $q) {
    var d = $q.defer(),
    resolved = false;

    var self = this;
    this.ready = d.promise;

    document.addEventListener('deviceready', function() {
        resolved = true;
        d.resolve(window.cordova);
    });

    // Check to make sure we didn't miss the 
    // event (just in case)
    setTimeout(function() {
        if (!resolved) {
            if (window.cordova) d.resolve(window.cordova);
        }
    }, 3000);
});

1 个答案:

答案 0 :(得分:0)

我不知道角度js,但你可以像设备rady那样使用backbutton

    document.addEventListener("backbutton", onBackKeyDown, false);

    function onBackKeyDown() {
        // Handle the back button

   }