What is the suggested way to define global variable in new UI5 webide project.
sap.ui.define([ "sap/ui/core/mvc/Controller" ], function(Controller) { "use strict"; return Controller.extend("test.controller.View1", { oView: null, onInit: function() { oView = this.getView(); }, }); });
When defined as above , i am facing an error that oView is not defined.
I have another ui5 project where controller was defined in a different way and working fine.
sap.ui.controller("test.view.main", { oView: null, onInit: function() { oView = this.getView(); },
Why does the way controllers defined for each version. Its getting tough to catch up the pace the changes are being made to project definitions at regular intervals.
Hi Michael,
The first option should work fine. I am not able to show on Web IDE, but here is a JS Bin: JS Bin - Collaborative JavaScript Debugging
Select any item to see view ID in alert.
Regards,
Sai.
Hi Micheal Bielawa,
Its not good idea to use global variables in your application, but still in your code you used use strict
keyword because of that its not allowing global variable declaration. you can remove that keyword and declare it nomally.
or else you can store your variable in window object (ex: window.name) or parent (ex: parent.name)
if your using "use strict".
sap.ui.define([
"sap/ui/core/mvc/Controller"
],
function(Controller) {
"use strict";
return Controller.extend(
"test.controller.View1",
{
oView:
null,
onInit:
function() {
window.oView = this.getView();
or
parent.oView = this.getView();
},
});
});
Thanks & Regards
Venkat
Add a comment