Answer the question
In order to leave comments, you need to log in
Why is the variable not updated immediately after the http request?
Hello. I'm new to angular so I'm asking for help explaining some of the nuances.
Question: why are the variables not updated immediately after the request?
So we have a controller, a factory and a file handler
Factory
app.factory('ld',function($http)
{
text="11111";
$http.post('php5.php').success(function(d){text=d;});
return {al:function(){console.log(text)}}
});
app.controller('cont',function($http,ld)
{
ld.al();
setTimeout(function(){ld.al();},1000);
});
header('Content-Type: application/json');
$text="22222";
echo json_encode($text);
11111
22222
Answer the question
In order to leave comments, you need to log in
God, format the code properly. And give adequate names to controllers and services...
app.controller('cont', ['$http', '$timeout', 'ld', function($http, $timeout, ld) {
ld.al();
$timeout(function(){ld.al();},1000);
}]);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question