未捕获的ReferenceError:未定义$ http

时间:2016-07-11 16:21:58

标签: javascript jquery angularjs

我使用AngularJS框架使用$ http时遇到了一些麻烦。我已经阅读了其他几篇关于此错误的帖子,但我无法弄清楚我做错了什么。任何帮助将不胜感激。错误是“未捕获的ReferenceError:$ http未定义'代码是:

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')
  });
}

1 个答案:

答案 0 :(得分:2)

尝试在控制器中包含$ http,如下所示:

.controller('MyController', ['$http', function ($http) {}];