1

I would like to know how can I use the scope.hello value outside the success function in my controller. Here is where its getting populated in my controller file:

$http.get(BaseUrl().url + 'jury/UpcomingEvents?someID=' + someID)
     .success(function (response) {
         $scope.UpcomingEvents = response;
         $scope.hello= $scope.UpcomingEvents[0].EventID;
     });

I want to be able to use the value of $scope.hello in another array outside the http.get function like so:

var Count=3;
$scope.Total= $scope.hello + Count

so that I can output $scope.Total in my html file as following.

{{Total}}

Right now, $scope.hello remains undefined as its not retaining the value from the success function as I understand, it is an asynchronous function.

Is there a way to use this value in other places in my controller?

Thanks.

1 Answer 1

1

Why cant you just do this,

var count = 3;
$http.get(BaseUrl().url + 'jury/UpcomingEvents?someID=' + someID)
     .success(function (response) {
         $scope.UpcomingEvents = response;
         $scope.hello= $scope.UpcomingEvents[0].EventID;
         $scope.Total= $scope.hello + Count
});
Sign up to request clarification or add additional context in comments.

3 Comments

I can do that, but I actually would be editing the entire array Upcoming Events and then have to present a new array in the html. Should I do that all inside the success function? Is that a recommended method and would that work? Thanks a lot for your help.
you can create a function to do that and pass the value to that
Yes it did! I accepted your answer! As per your suggestion, I used the result inside the success function and that worked! Thanks!

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.