AngularJS ng点击和$http post错误

AngularJS ng点击和$http post错误,angularjs,Angularjs,AngularJS theApp.controller('MenuSideController', ['$scope', 'CategoryService', function ($scope, CategoryService){ CategoryService.getList() .success(function(list){ $scope.list = list; }); $scope.menuType = function(id) {

AngularJS

theApp.controller('MenuSideController', ['$scope', 'CategoryService', 
  function ($scope, CategoryService){
    CategoryService.getList()
    .success(function(list){
        $scope.list = list;
    });
    $scope.menuType = function(id) {
        $http.post('post_es.php', {'cat': $scope.username, 'pswd': $scope.userpassword, 'email': $scope.useremail}).success(function(data, status, headers, config) {
            if (data.msg != '') {
                $scope.msgs.push(data.msg);
            } else {
                $scope.errors.push(data.error);
            }
        }).error(function(data, status) { // called asynchronously if an error occurs
            // or server returns response with an error status.
            $scope.errors.push(status);
        });
    }
  }
]);
HTML

<li ng-repeat="company in list"><a href="#" ng-click="menuType(company.id)">{{ company.name }}</a></li>
  • 使用上述方法,我在单击
    menuType
    时收到此错误

    ReferenceError:$http未定义


    您必须将
    $http
    服务作为依赖项传递

    theApp.controller('MenuSideController', [
      '$scope',
      'CategoryService', 
      '$http', 
      function ($scope, CategoryService, $http) {
    

    这使其可在控制器中使用。过滤器、指令和服务也是如此。

    谢谢,我对AngularJS很陌生,现在就知道了