Skip to Content
author's profile photo Former Member
Former Member

how to set global variable in ui5 controller

I am learning ui5 via webide and have to assign a global variable that can be used in any controller. I tried assigning a new variable

'var testglobalvariable=null;' in the controller as below, but ide throws an error everytime. How to assign ?

var testglobalvariable=null;
sap.ui.define([
  "sap/ui/core/mvc/Controller"
], function(Controller) {
  "use strict";


  return Controller.extend("testapp.controller.View1", {


  });
});
Add comment
10|10000 characters needed characters exceeded

1 Answer

  • Posted on Jun 30, 2016 at 06:06 PM

    you can add it to your model... and then you can access this variable from the model through your application

    get a handle of your model... then... you can set it via..

    model.setProperty('/varName', value)

    and to retrieve it

    model.getProperty('/varName')

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member

      thanks for suggestion , but i cannot use it via model everytime. as i have other functions which accesses it and plays around this variable before assigning back to view/model again.