In controllers there is such a function that sets the parameters of the schedule:

function sparklineChartCtrl() { var longLineData = [34, 43, 43, 35]; var longLineOptions = { type: 'line', lineColor: '#17997f', fillColor: '#ffffff' }; this.longLineData = longLineData; this.longLineOptions = longLineOptions; } 

The graph itself is displayed like this:

 <div ng-controller="sparklineChartCtrl as spark"> <div sparkline spark-data="spark.inlineData" spark-options="spark.inlineOptions"></div> </div> 

The graph is built and everything works when the longLineData array longLineData registered by hands in the controller (as here in the example). But when trying to take an array through the $http.get() request, nothing works.

The task is using $http.get('url') to transfer the value of the array to the variable this.longLineData . I am completely new, I tried differently, it does not work.

    1 answer 1

    This is done with the help of the construction of the form

     var self = this; //Выполняем запрос на сервер //при успешном выполнении которого в переменную `longLineData` //будет записан результат $http.get('url').then(function(result) { self.longLineData = result.data; console.log('self.longLineData:', self.longLineData); }); 
    • formatted your question a bit, added a comment. - Bald
    • var self = this; $http.get('url').then(function(result) { self.longLineData = result.data; }); console.log(this.longLineData); @Bald, @ a-bobkov, is displayed in the this.longLineData console as undefined . What's wrong? - Dmitry
    • @Dmitry I assume that the result of the request to the server was not successful, try to change it like this: return $http.get('url').then(function(result){ console.log('success'); console.log(result.data);}, function(response){console.log(response);}); and look in the console what is displayed - Bald
    • @Bald, html request fulfills normally. With your code, the following answers are given in the logs: success and Object data:Array[30] . Those. inside $http.get() everything is fine. But when you try to bring the data to a higher level, beyond the limits of the function, they turn into undefined . - Dmitry
    • @Dmitry console.log must be entered into a function and delivered after assignment. I added in response. - a-bobkov