2

I have a function like this:

 $scope.GetDays = function() {
         $http.post("core/ajax/LoadDays.php").success(function(data){
                 return data[0].days;
    }); 

};

And in LoadDays.php I have this json:

 [{"days":"1"}]

If I do console log It will return correct: 1. But, the problema is When I call it on my HTML code. I recive a looping erros : $rootScope:infdig

How can I do this?

Sorry for my english

0

1 Answer 1

2

Read up on the concept of Ajax (asynchronous javascript), because that's what you're doing here.

You should do something like this:

$scope.GetDays = function() {
         $http.post("core/ajax/LoadDays.php").success(function(data){
                 $scope.days= data[0].days;
    }); 

};

And then use {{days}} in your html. Days will be filled with data shortly after you call GetDays(), depending on how fast the server request is handled.

Sign up to request clarification or add additional context in comments.

3 Comments

If you define that function in your controller and that controller is defined in the html, you can simply call it with {{getDays()}} within the scope of that controller. If that doesn't work, you misconfigured something, but it's impossible to find out what, from the code that you posted.
Yes, when I do that {{getDays()}} I get the error $rootScope:infdig, I will try to find out whats is going on. Thank you.
@MinearenaMine you don't need curly braces to call scope function, just ng-click="getDays()"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.