javascript - How can I create a scope function the return json in Angular? -
i have function this:
$scope.getdays = function() { $http.post("core/ajax/loaddays.php").success(function(data){ return data[0].days; }); };
and in loaddays.php have json:
[{"days":"1"}]
if console log return correct: 1. but, problema when call on html code. recive looping erros : $rootscope:infdig
how can this?
sorry english
read on concept of ajax (asynchronous javascript), because that's you're doing here.
you should this:
$scope.getdays = function() { $http.post("core/ajax/loaddays.php").success(function(data){ $scope.days= data[0].days; }); };
and use {{days}}
in html. days filled data shortly after call getdays()
, depending on how fast server request handled.
Comments
Post a Comment