-1

I have a little problem. The API data from the code below appears normally on the console, it returns an array with the data, but I can't return them to use them in the front-end. PS: that "name here!" I can use it on the front, the query cannot.

I'm using angularJS.

$scope.getCharacters = function() {
      $scope.teste = "name here!";
      axios.get(baseUrl + "/characters" + complemento)
        .then(function (res) {
          console.log(res.data.data.results) // returns API data normally, communication is working
          var heroes = res.data.data.results;
          return heroes;
        })
        .catch(function (err) {
          console.log(err)
        });
        
        console.log(heroes)
    }

$scope.getCharacters();
1
  • I don't understand what your question is. Have you checked the Network tab of your dev tools to confirm that the HTTP call succeeded and has the data you're expecting? Commented Dec 27, 2021 at 20:17

1 Answer 1

0

You need to set $scope.getCharacters(); to some variable. You are calling the code but it's not being saved anywhere to be used.

$scope.heroes = $scope.getCharacters(); is a possible solution.

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

Comments

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.