改变" esc"离子2 app中的关键行为

时间:2018-01-02 18:34:14

标签: browser ionic2

当我在浏览器中测试(或使用)我的离子2应用程序时,如果一个模态打开并且我点击了#34; esc"我的键盘的键,模态解散。
我想控制我的模态如何被我可以自定义的功能解雇。与移动平台的customize back button actions类似。

换句话说,我想转发" esc"关键命中事件到我自己的功能。
有什么建议吗?

1 个答案:

答案 0 :(得分:1)

您可以覆盖功能 dismiss()

    let alert = this.alertCtrl.create({
        title: 'Hello world'
    });

    // Just override this function:
    alert.component.prototype.dismiss = function() {
         console.log('ESC button hit handled');             
    }

    // For turn back:
    /*
    alert.component.prototype.dismiss = function (role) {
        var opts = {
            minClickBlockDuration: 400
        };
        return this._viewCtrl.dismiss(this.getValues(), role, opts);
    };  
    */

    alert.present();

修改

另外我认为你可以使用ionViewCanLeave()

在模态视图组件中添加:

    ionViewCanLeave() {

        // ... some code ...

        return false;
    }