Search code examples
sapui5

How to call method without oEvent


How to call Event handler from a method of the controller?

<Button text="click" tap=".BtnTap" />
BtnTap: function(oEvent) {
  console.log("Button Tap");
},

doSomething : function() {
  BtnTap();
},

I want same BtnTap() call from another function in the controller.
It doesn't seem to be possible to access oEvent from another function.


Solution

  • it is not so elegant to directly to call the event handler. Maybe you can extract the logic in the event handler to another function.

    BtnTap: function(oEvent) {    
        console.log("Button Tap");
        this.btnTapHelper();
    }
    
    btnTapHelper: function() {
        //logic here
    }
    
    doSomething : function() {
        this.btnTapHelper();
    }