0

I am currently having an issue with populating some textareas with text. When I step through with the debugger it works fine, however when I let it run normally it will only populate the fields with the data on the second time it is loaded. This leads me to believe that the issue is to do with how the page is loading. I am trying to delay the execution of my method that attempts to populate the fields using callbacks however I am completely new to this method of programming in JS, let alone AngularJS.

I keep getting the Callback is not a function error whenever I try this :

 $scope.StudyAndUnderstandingContent = []
$http.post('url', {stepNumber: currentStep.currentstep})
.then(function success(response, getCallback) {
    $scope.StudyAndUnderstandingContent = response.data.step;
    getCallback();
});

And here is my callback function:

function getCallback()
{
    $http.post('url2', getData)
    .then(function(response)
    {
        angular.forEach(response.data.answer, function(value, key)
        {
            $scope.answers.push(response.data.answer[key]); 
        });

        $scope.textBoxes = [];
        angular.forEach(angular.element($(".inline-q")), function(value, key)
        {
            $scope.textBoxes.push(value);
            $scope.textBoxes[key].value = $scope.answers[key].answer;
        });
    });
}

I have looked at the other questions whilst also trying to find my own fix, but I have made 0 progress. Any help would be appreciated.

7
  • is it outside of angular's $scope? Commented Mar 6, 2017 at 11:02
  • Without traceing your codw just a quick thought... you probably need to wait for the page to load completely... Commented Mar 6, 2017 at 11:03
  • do you mean getCallback is not a function? Commented Mar 6, 2017 at 11:04
  • it's sitting inside of the controller, so it shouldn't be a reference issue, I use this method elsewhere in the code and it works fine, I might move the method outside of the controller and pass it in and see if that works. Commented Mar 6, 2017 at 11:05
  • @DarrenSweeney yes, I was generalising, sorry. Commented Mar 6, 2017 at 11:05

2 Answers 2

1

No need to pass callback function in success

$scope.StudyAndUnderstandingContent = []
$http.post('url', {stepNumber: currentStep.currentstep})
.then(function success(response) {
    $scope.StudyAndUnderstandingContent = response.data.step;
    getCallback();
});

See the document for $http

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

1 Comment

this worked perfectly, thanks a tonne! Can't believe I didn't think to do this straight away.
1
    $http.post('url', {stepNumber: currentStep.currentstep}).then(

        function successCallback(response) {
          $scope.StudyAndUnderstandingContent = response.data.step;
          getCallback();
        },
        function errorCallback (response) {
         // handle error
        }
      );

2 Comments

this was correct but @Gaurav answered first, thanks anyways :)
no problem but you can appreciate the effort by giving up vote to gourov :) @geolaw

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.