Having a javascript file structure that looks like this:
class RandomCtrl {
constructor(randomService) {
this.randomService = randomService;
...
}
$onInit() {
getData.call(null, this);
}
...
}
function getData(RandomCtrl) {
...
}
function getChart(data) {
if (!data) {
return;
}
const chartOptions = getWeekHourlyOptions(data);
const allCols = [].concat(chartOptions.dataColumns);
allCols.push(["x"].concat(_.map(chartOptions.xAxis, element => moment(element).valueOf()));
const xVals = xAxisValues(chartOptions.xAxis);
...
}
...
RandomCtrl.$inject = ['randomService'];
export const Random = {
bindings: {
data: '<',
siteNames: '<'
},
templateUrl: randomPageHtml,
controller: RandomCtrl
};
The objective is to retrieve the value of allCols
and assign it to a variable. An attempt was made by adding return allCols;
to the end of the getChart()
method and calling it within the $onInit()
function.
Various methods were tested including:
const wow = getChart();
const wow = getChart(this);
const wow = getChart.call(null, this);
However, all attempts resulted in undefined for the variable 'wow'. Any suggestions on how to resolve this issue?