【发布时间】:2016-11-13 16:24:01
【问题描述】:
我在使用 AngularJS 框架使用 $http 时遇到了一些麻烦。我已经阅读了有关此错误的其他几篇文章,但我无法弄清楚我做错了什么。任何帮助将不胜感激。错误是'Uncaught ReferenceError: $http is not defined',代码是:
function removePupil(val) {
var string = 'Jon:jon@aaa.com:George:george@aaa.co.uk:Matthew:matthew@aaa.com:';
var pupilNowRemoved = string.replace(val, '');
var data = {
"customer[id]": {{ customer.id }},
"metafield[customer.pupils]": pupilNowRemoved,
};
$http.post('/a/custmeta', $.param(data),
{"headers" : {"Content-Type": "application/x-www-form-urlencoded; charset=UTF-8"}
}).success(function(data, status, headers, config) {
console.log('Removed pupil')
}). error(function(data, status, headers, config) {
console.log('Did not remove pupil')
});
}
【问题讨论】:
-
你有没有在你的控制器函数中注入
$http作为依赖? -
@Pankaj 不,我不应该在第一行之后有这个:
app.controller('myCtrl', ['$scope', '$http', function($scope, $http){和倒数第二行)]};?谢谢你的帮助,马特 -
是的,你是对的,你也可以参考下面的答案。
标签: javascript jquery angularjs