类型错误:无法读取 AngularJS 上未定义的属性“get”
TypeError: Cannot read property 'get' of undefined on AngularJS
我是AngularJS的新手,我得到了这个错误。这是我的代码:
app.factory('NotificationService', function($http){
var factory = {};
factory.getNotificationList = function($http){
var url = "http://some/url";
return $http.get(url);
}
return factory;
});
app.controller('NotificationListController', function($scope,$http, NotificationService) {
var notificationList = NotificationService.getNotificationList();
notificationList.then(function(response){
console.log(response);
$scope.notificationData = response.data;
return response;
});
});
我很困惑我的错误在哪里。错误消息是:
类型错误: 无法读取未定义的属性"get" at Object.factory.getNotificationList (http://localhost:63342/EmailNotification/js/email-angular.js:15:21)
您收到此错误是因为$http
工厂中未定义。
您可以通过将其传递给工厂来修复它,如下所示:
app.factory('NotificationService', ['$http', function ($http) {
var factory = {};
factory.getNotificationList = function() { // Remove the `$http` parameter from here.
var url = "http://some/url";
return $http.get(url);
}
return factory;
}]);
简单可能的原因是$http
被传递了两次。将任何参数传递给函数时,这些变量的闭包会发生变化
在此处查看示例
var a =10;
var b= 20;
var abc = function()
{
document.getElementById("first").innerHTML = a + b;
}
var pqr = function(a,b)
{
document.getElementById("second").innerHTML = a + b;
}
abc();
pqr();
在这个例子中,虽然声明了变量 a,b,但第二个函数 pqr()
将返回 NaN,直到我们显式传递参数
相关文章:
- 将对象作为参数传递后的未定义属性
- 检查链接对象形式中未定义属性的最佳实践是什么
- PhantomJS中的evalute内部未定义属性
- 访问数字类型的未定义属性
- 如何处理未定义属性的未定义属性 javascript 类型错误
- 返回未定义属性的脚本
- 类型错误:无法读取 ng-repeat 的未定义属性
- JavaScript-Disqus如何处理其“;disqus_config”;包含未定义属性的函数
- 是对HTMLElement#样式的未定义属性的赋值的返回值,保证与赋值相同
- 最好检查未定义属性或设置为空
- 如何解决这个未定义属性的node.js错误?
- 如何在JavaScript中挽救对象的未定义属性?
- AngularJS和PHP -注意:未定义属性:stdClass
- 主干模型删除未定义属性
- if else子句中未定义对象的未定义属性
- Javascript数组问题:无法读取未定义属性
- 当尝试使用未定义属性进行筛选时,Lodash将排除项
- 在Javascript数组的中途未定义属性
- Knockout arrayForEach未定义属性
- javascript中未定义属性的简写,初始化和赋值属性