When defining an EventHandler function in your Controller you may want to pass the application context to it in order to be able to manipulate the application’s View’s elements. As of now this is the most convenient method of being able to access the application context anywhere in your SAP UI5 / OpenUI5 application.

  1. Declare a global variable attaching the context of your application to the window object in OnInit()
  2. Now you can just access the variable from every function. This is possible, because the JavaScript window variable can be accessed in any scope.

Example code

onInit: function() {
  //the applications context is "this"
  //attach it to the window object
  window.context = this;
  //now you can access the context by calling window.context at any time.