cancel
Showing results for 
Search instead for 
Did you mean: 

How to read js file data in ui5 controller

0 Kudos

Here is my constants.js file code , which contains the below data (static data).

var SORT_ORDER = {
    ASC : "ascending",
    DSC : "descending"
};
var YES = "yes";
var NO = "no";

i wanted to read this data in ui5 controller code.

sap.ui.define([
	'jquery.sap.global',		
	'sap/ui/core/mvc/Controller',
	'sap/ui/model/json/JSONModel',       
        "./constants"
], function (jQuery, Controller, JSONModel, constant) {
    "use strict";
    var PageController = Controller.extend("UI5Script.controller.Page1", {

        onInit: function () {
   
        var sortorder = constant.SORT_ORDER.ASC; // which throws error
},

 });
    return PageController;
});

Accepted Solutions (1)

Accepted Solutions (1)

0 Kudos

Changing the path doesn't helps.

I found the solution by using the javascript "window" object

(function (window) {
    "use strict";  


    window.appConstants = {       
        YES: "yes",
        NO: "no"   
    };
}(window));

you can access the above constant in UI5 as shown below

appConstants.YES

Answers (1)

Answers (1)

Former Member
0 Kudos


try

"UI5Script/constants" instead of

"./constants"