0

The following controller is producing the error message "Cannot call method 'jsonp' of undefined". I suspect that I am not injecting $http properly. Can someone tell me what I've done incorrectly?

'use strict';

/* Controllers */

angular.module('myApp.controllers', []).

  controller('ImagesCtrl', [function ImagesCtrl ($scope, $http) {
    $http.jsonp('http://localhost:3000/image?quantity=1&language=Cantonese&callback=JSON_CALLBACK')
    .success(function(data){
      console.log(data);
      $scope.image = data;
    }); 

  }])


  .controller('CaptionsCtrl', [function() {

  }]);
hughesdan
  • 3,019
  • 12
  • 57
  • 80

1 Answers1

1

I guess you are not injecting dependencies properly

app.controller(<controller_name>, ['$scope', function($scope) {}]);

in your case that should be

app.controller('ImagesCtrl', ['$scope', '$http', function($scope, $http) {}]);

Or if you prefer not to use annotations (which are good for minification):

app.controller('ImagesCtrl', function () {
    console.log("in the controller");
});
Eduard Gamonal
  • 8,023
  • 5
  • 41
  • 46