类型错误:无法读取未定义的属性“get" [英] TypeError: Cannot read property 'get' of undefined

查看:42
本文介绍了类型错误:无法读取未定义的属性“get"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

$http.get('/contactList').
success(function(data){
    console.log('got http get');
}).
error(function(data) {
    $scope.error = true;
    $scope.data = data;
    return 'error name';
});

我在这部分代码中出现错误.我正在尝试在 Angular JS 中使用 $http.get 函数.我做错了什么吗?

I have an error with just this section of code. I am trying to use the $http.get function with Angular JS. Am I doing something wrong?

我不断收到错误消息.

推荐答案

正如其他评论者所说,您应该查看您的控制器声明,您需要注入"$http 服务:

As other commenters said you should look at your controller declaration, you need to 'inject' the $http service:

angular.module('myApp')
.controller('messageController', ['$scope', '$http', function($scope, $http){
  $http.get()
  .success()
  .error();
}]);

这篇关于类型错误:无法读取未定义的属性“get"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆