Reputation: 187
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.
Upvotes: 0
Views: 867
Reputation: 279
I'd usually say you communicate across controllers via the eventbus. So you would catch the tap event in your direct controller and submit another event which is then caught within the other controller.
The controller which is to capture the event has something like this:
sap.ui.getCore().getEventBus().subscribe('submitSomething', eventID, this.reactToSomething, this);
the emitter would something like this on tap:
eventBus.publish('submitTmpData', eventID);
and the aforementioned capturing controller's event handler looks something like this.
reactToSomething: function(type, eventid){
...
},
You can also add custom data to your events.
Cheers Michael
Upvotes: 1
Reputation: 5713
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();
}
Upvotes: 0