Javascript ReferenceError:$http未定义Angularjs
即使我在控制器中注入了$http,我仍然会遇到这个错误Javascript ReferenceError:$http未定义Angularjs,javascript,angularjs,Javascript,Angularjs,即使我在控制器中注入了$http,我仍然会遇到这个错误 app.controller('myCtrl', ['$scope', '$http', function($scope, $http) { $scope.user = { name: '', address: '', email: '', date: '', time: '', phone: '', zipcode: 0
app.controller('myCtrl', ['$scope', '$http', function($scope, $http) {
$scope.user = {
name: '',
address: '',
email: '',
date: '',
time: '',
phone: '',
zipcode: 0,
};
}]);
当我试图在这段代码上发布http
请求时
$scope.reserve = function() {
$http.post('/user'
$scope.user).success(function(response) {
console.log(response);
});
}
它给了我$http未定义错误。您将在中终止您的函数
函数($scope,$http){}
您应该在函数中编写控制器代码。您是否在控制器函数中引用$http?另外,在“/user”之后似乎缺少逗号。如果
myCtrl
的字面定义如上所述,那么它当然与其他代码段无关,因为控制器被定义为空函数。这两段代码之间的关系到底是什么?