R
R
Roman Kuzmenko2016-09-11 15:37:11
JavaScript
Roman Kuzmenko, 2016-09-11 15:37:11

How to set rootScope in http.get?

Hello! There is the following construction, the result of which is "undefined"
In response, we have an array. How to correctly set a global variable in http.get?

$http.get("http://xxx").success(function (response) {
$rootScope.labels = response;
});
console.log($rootScope.labels);

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alex, 2016-09-11
@Kozack

And so?

$http.get("http://xxx").success(function (response) {
    $rootScope.labels = response;
    console.log($rootScope.labels);
});

S
Stepanya, 2016-09-19
@Stepanya

Use $rootScope less.
Your question is not correct, $rootScope is available in the success function. The problem is that it is only called when a response comes from the server.
You most likely use $rootScope.labes when initializing the controller, so you need to add the actions that you are trying to do before the data was received to the success function

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question