'how to set a variable that is shared between multiple controllers
Is it a good idea to set a js file(in util folder) which return a global object which will keep a list of different map of variables . So in the index.js I can pass the app variable and followed by accessing it from controller.
sap.ui.define(["sap/ui/base/ManagedObject"], function (ManagedObject) {
"use strict";
let globals = {};
return globals;
});
and in index.js
sap.ui.define(
[
"sap/ui/base/ManagedObject",
"zap/util/globals",
],
function (ManagedObject, globals) {
"use strict";
let oApp = new sap.m.App();
globals.oApp = oApp;
});
and in controller event handler
sap.ui.define(
["sap/ui/core/mvc/Controller", "zap/util/globals"],
function (Controller, globals) {
"use strict";
return Controller.extend("zap.controller.Master", {
onListPress: function (oEvt) {
let oApp = globals.oApp;
}
});
});
Solution 1:[1]
You can create a model, and load it in the manifest.json, so it would be accessible from each part of your application.
{
"models": {
"globalModel": {
"type": "sap.ui.model.json.JSONModel",
"uri": "Models/GlobalModel.json"
}
}
}`
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | hauseyo |
