I have a javascript function that retrieves a JSON object and the returns that value after processing it into a dataTable. Where I am running into trouble is returning that value to an Angular Scope. How would I retrieve the returned value inside the Angular Scope function?
Javascript
function sessionsLength(){
loadReport('session-length', 'days', oneMonth).then(function (results) {
var i
var rows = [];
for (i = 0; i < results.length; i++) {
var c = [];
c.push(
{v: results[i].timestamp.valueOf()},
{v: results[i].data.tenth},
{v: results[i].data.fiftieth},
{v: results[i].data.ninetieth}
);
var segment = {c:c};
rows.push(segment);
}
var dayPlot = {
id: 'day',
label: 'Day',
type: 'number'
};
var tenthPlot = {
id: 'tenth',
label: 'Tenth',
type: 'number'
};
var fiftiethPlot = {
id: 'fiftieth',
label: 'Fiftieth',
type: 'number'
};
var ninetiethPlot = {
id: 'ninetieth',
label: 'Ninetieth',
type: 'number'
};
var cols = [dayPlot,tenthPlot,fiftiethPlot,ninetiethPlot];
var plot = {
type:'Line',
data:{
'cols':
cols
,
'rows':
rows
},
options: {
chart:{
title: '',
subtitle: ''
},
height: 500
}
};
return plot;
console.log(plot);
});
}
Angular Controller
'use strict';
angular.module('triAngularElements').
controller('GoogleChartsLineController', function ($scope) {
$scope.chartData = sessionsLength();
});