【发布时间】:2014-10-06 06:12:30
【问题描述】:
在 MEAN 堆栈应用程序中运行以下代码时,我不断收到上述错误:
$scope.completelesson = function(lessonindex, type) {
//a variable that will be appended to 'level' in order to access the level property of the user
var x = lessonindex + 1;
var level = 'level' + x;
var toupdate = {
level: level,
type: type,
};
console.log(toupdate);
$http({method: 'POST', url: '/users/updatelevel'}).success(function(response) {
$location.path('/dashboard');
});
};
这是完整的错误信息:
TypeError: undefined is not a function
at Scope.$scope.completelesson (http://localhost:3000/modules/dashboard/controllers/lesson.client.controller.js:64:13)
at http://localhost:3000/lib/angular/angular.js:10795:21
at http://localhost:3000/lib/angular-touch/angular-touch.js:441:9
at Scope.$eval (http://localhost:3000/lib/angular/angular.js:12632:28)
at Scope.$apply (http://localhost:3000/lib/angular/angular.js:12730:23)
at HTMLButtonElement.<anonymous> (http://localhost:3000/lib/angular-touch/angular-touch.js:440:13)
at http://localhost:3000/lib/angular/angular.js:2843:10
at forEach (http://localhost:3000/lib/angular/angular.js:325:18)
at HTMLButtonElement.eventHandler (http://localhost:3000/lib/angular/angular.js:2842:5)
奇怪的是,这段代码以前可以工作 - 突然就停止了。该函数一直运行到 $http 为止。我知道这一点是因为 console.log() 记录了正确的对象,但 $http 请求从未记录到节点控制台。
我的 AngularJS 文件是最新的 (1.2.22)。
知道什么可能导致此错误消息以及如何修复它吗?
感谢您的帮助。
编辑:
这是我的控制器定义的代码:
angular.module('dashboard').controller('lessonController', ['$scope', 'Authentication', '$location', 'lesson', '$sce', '$http',
function($scope, Authentication, $location, lesson, $sce, $state, $http) {
【问题讨论】:
-
第 64 行是什么?
-
顺便说一句,您是否为
$http注入了依赖项。像app.controller('controller',['$scope','blah', function($scope, blah,$http){//and trying to access $http ?}])这样的东西你能显示你的控制器定义吗?这也可能导致这样的错误。 plnkr.co/edit/MshJBB?p=preview 也尝试调试看看哪个方法是未定义的。无论是$http还是success -
@UmurKontaci - $http 函数在第 64 行。
-
@PSL - 是的,我为 $http 注入了依赖项。我会将控制器定义的代码添加到我的原始帖子中。
-
注入的 deps 数量与构造函数中的参数数量不匹配。 $ state 在你的情况下是 $ http
标签: javascript node.js angularjs mean-stack