Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

Declaring Global variables in SAP UI5 javascript files

Hi,

I want to create global variables in the views and controllers of SAP UI5 application.

Consider a scenario like this :

sap.ui.controller("testController", {

   loadData: function(oEvent){

           

globalVariable = oEvent.someAttribute;

   },

   onDataModelLoaded : function(data) {

alert(globalVariable );

             },

});

So I want to use this globalVariable accessed by all the functions inside the controller. But unfortunately this variable can never be accessed outside the scope of the given function.

I tried declaring the variable like:

sap.ui.controller("testController", {

globalVariable:0,

   loadData: function(oEvent){

  

globalVariable = oEvent.someAttribute;

   },

   onDataModelLoaded : function(data) {

alert(globalVariable );

    },

});

But this is useless too. I will be thankful for any help regarding this.

Best Regards,

Riswan

Former Member
Not what you were looking for? View more on this topic or Ask a question