1

I'm trying to make an HTTP GET to an API and I'm not getting anything back in the console log, so I'm assuming this function isn't running.

This is the jsfiddle I'm trying to recreate in my Angular app, which has the proper data structure:

http://jsfiddle.net/bgoldste/keam6q9o/

Here's controller.js

.controller('GamesCtrl', function($scope, $http) {
    function GamesCtrl($scope, $http) {
        console.log("did this run");
        $http(
        {
            method: 'GET',
            url: 'https://www.kimonolabs.com/api/bzq274q4?apikey=JfagXh7xfxWsnWGzLAKpBIrTFwENcGY6',
            headers: {
                'authorization': 'Bearer xOZHZE4sit0Pe6VGqsOQn5jKPpA5QpG3'
            }
        }).
        success(function (data) {
            $scope.data = data['results']['collection1'];
        });
    }
})

And here's games.html

<ion-view title="Games" ng­controller="GamesCtrl">
  <ion-content>
    <ion-list>
      <ion-item ng-repeat="row in data">
        {{row['property1']['src']}}
      </ion-item>
    </ion-list>
  </ion-content>
</ion-view>

I'm not even seeing a network request in the console from that GET

8
  • There is not enough information given here for us to have any idea without asking 20 questions. You provided no information about status of request, data structure returned etc. Commented Dec 20, 2014 at 4:19
  • I just edited the question with a link to the jsfiddle I'm trying to reproduce jsfiddle.net/bgoldste/keam6q9o Commented Dec 20, 2014 at 4:20
  • Correct, but my project locally is not bringing back data. Commented Dec 20, 2014 at 4:23
  • so what about status of request itself? Inspect it in your network tab. Use an error handler also Commented Dec 20, 2014 at 4:24
  • Make sure your url is correct and second thing if locally it is not working please check that it is not issue of firewall. Commented Dec 20, 2014 at 4:24

1 Answer 1

1

You have two nested function definitions - the second one won't even be called. Try this instead:

.controller('GamesCtrl', function($scope, $http) {
    console.log("did this run");
    $http(
    {
        method: 'GET',
        url: 'https://www.kimonolabs.com/api/bzq274q4?apikey=JfagXh7xfxWsnWGzLAKpBIrTFwENcGY6',
        headers: {
            'authorization': 'Bearer xOZHZE4sit0Pe6VGqsOQn5jKPpA5QpG3'
        }
    }).
    success(function (data) {
        $scope.data = data['results']['collection1'];
    });

})
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.