Would like to call configuration function defined at file B.js from File A.ts and set the return object in a config variable.
However I could not access the correct value for the config var or var x which are both reside outside of the 'then' function.
i could get the correct value inside the 'then' function, but not outside the 'then' function.
Code in A.tx
import {configuration} from "../../B";
var x = configuration("typeA").then(function(data){
console.log("inside then fct: "+ JSON.stringify(data));
config=data;
return (data);
})
console.log("config"+JSON.stringify(config));
console.log("outside then fct: "+ JSON.stringify(x));
Code in B.js
exports.configuration = function (type) {
return new Promise(function (resolve, reject) {
var url = '/api/code/configuration/' + type;
c.makeRequest('get', url)
.then(function (data) {
console.log("confi: "+JSON.stringify(data));
resolve(data);
})
.catch(function (error) {
reject(error);
});
});
};