I'm doing something with Chart.js. I am using this function ($scope.getAreas) to get the information to build the charts. When I print the variables ($scope.AreasInteres) outside the "then" function it returns "undefined".
var app = angular.module('App', ["chart.js"]);
app.controller('chartsCtrl', function($http, $scope) {
var vt = this;
vt.chartPieLabels = ["Revistas", "Libros", "Internet", "Otros"];
vt.chartPieCharts = [152, 51, 68, 210];
vt.chartPieOptions = {
maintainAspectRatio: true,
responsive: true
};
vt.chartPieColours =['#494750', '#999999', '#cc3321', '#2fb467'];
$scope.AreasInteres;
$scope.getAreas = function(){
$http({
url: 'contarAreasInteres/',
method: 'GET'
}).then(function (response) {
$scope.AreasInteres = response.data;
console.log($scope.AreasInteres);
});
console.log($scope.AreasInteres);
};
$scope.getAreas();
});
I've been using the same way to get things from REST in the same project and I didn't have problems. Thanks in advance.