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() {

  }]);

1 Answer 1

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