不能调用未定义的方法'JSONP“在Angular.js控制器 [英] Cannot call method 'jsonp' of undefined in Angular.js controller
本文介绍了不能调用未定义的方法'JSONP“在Angular.js控制器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
以下控制器产生错误消息无法调用未定义的方法'JSONP'。我怀疑,我无法正常注入$ HTTP。谁能告诉我,我已经做了不正确的?
使用严格的;/ * *控制器/angular.module('myApp.controllers',[])。 控制器('ImagesCtrl',[功能ImagesCtrl($范围,$ HTTP){
$http.jsonp('http://localhost:3000/image?quantity=1&language=Cantonese&callback=JSON_CALLBACK')
.success(功能(数据){
的console.log(数据);
$ scope.image =数据;
}); }])
.controller('CaptionsCtrl',[功能(){ }]);
解决方案
我猜你没有正确注入依赖
app.controller(小于CONTROLLER_NAME>中['$范围',函数($范围内){}]);
在你的情况应该是
app.controller('ImagesCtrl',['$范围,$ HTTP',函数($范围,$ HTTP){}]);
或者,如果你preFER不使用注释(这有利于缩小):
app.controller('ImagesCtrl',函数(){
的console.log(在控制器);
});
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() {
}]);
解决方案
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");
});
这篇关于不能调用未定义的方法'JSONP“在Angular.js控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文