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" ngcontroller="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
-
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.charlietfl– charlietfl2014年12月20日 04:19:00 +00:00Commented 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/keam6q9obeaconhill– beaconhill2014年12月20日 04:20:28 +00:00Commented Dec 20, 2014 at 4:20
-
Correct, but my project locally is not bringing back data.beaconhill– beaconhill2014年12月20日 04:23:10 +00:00Commented Dec 20, 2014 at 4:23
-
so what about status of request itself? Inspect it in your network tab. Use an error handler alsocharlietfl– charlietfl2014年12月20日 04:24:32 +00:00Commented 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.dotnetstep– dotnetstep2014年12月20日 04:24:42 +00:00Commented Dec 20, 2014 at 4:24
1 Answer 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'];
});
})
answered Dec 20, 2014 at 4:44
Michael Kang
53k16 gold badges108 silver badges138 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
lang-js