【问题标题】:ReferenceError: $http is not defined Angularjs [duplicate]ReferenceError:$http未定义Angularjs [重复]
【发布时间】:2016-05-09 20:41:35
【问题描述】:

即使我在控制器中注入了 $http,我仍然会收到此错误。

app.controller('myCtrl', ['$scope', '$http', function($scope, $http) {
    $scope.user = {
        name: '',
        address: '',
        email: '',
        date: '',
        time: '',
        phone: '',
        zipcode: 0,
    };
}]);

当我尝试在此代码上发布httprequest 时

$scope.reserve = function() {
   $http.post('/user'
       $scope.user).success(function(response) {
       console.log(response);
   });
}

它给了我 $http is not defined 错误。

【问题讨论】:

  • 你是在控制器函数中引用 $http 吗? '/user' 之后似乎也缺少逗号。
  • 如果myCtrl字面上定义如上,那么当然与其他代码sn-p无关,因为控制器被定义为一个空函数。 这两段代码之间究竟是什么关系?

标签: javascript angularjs


【解决方案1】:

你正在终止你的函数

function($scope, $http){}

您应该在函数中编写控制器的代码。

【讨论】:

    猜你喜欢
    • 2012-11-25
    • 2015-08-26
    • 2014-06-17
    • 2016-07-07
    • 1970-01-01
    • 2016-10-27
    • 2020-12-26
    • 1970-01-01
    • 2012-09-07
    相关资源
    最近更新 更多