2013-07-04 31 views
0

以下控制器正在生成錯誤消息「Can not call method'jsonp'of undefined」。我懷疑我沒有正確注入$ http。有人能告訴我我做錯了什麼嗎?無法在Angular.js控制器中調用未定義的方法'jsonp'

'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

我猜你是不是在你的情況下妥善

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

注入依賴,應該是

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

或者,如果你不喜歡使用註釋(這有利於縮小) :

app.controller('ImagesCtrl', function() { 
    console.log("in the controller"); 
}); 
相關問題