debugging - 在 AngularJS 应用程序中查找错误行

标签 debugging angularjs

我刚开始玩 AngularJS,下面出现错误。

Error: Argument '?' is not a function, got Object
at assertArg (http://localhost/angular/project/scripts/vendor/angular.js:1039:11)
at assertArgFn (http://localhost/angular/project/scripts/vendor/angular.js:1049:3)
at http://localhost/angular/project/scripts/vendor/angular.js:4802:9
at http://localhost/angular/project/scripts/vendor/angular.js:4384:17
at forEach (http://localhost/angular/project/scripts/vendor/angular.js:137:20)
at nodeLinkFn (http://localhost/angular/project/scripts/vendor/angular.js:4369:11)
at compositeLinkFn (http://localhost/angular/project/scripts/vendor/angular.js:4015:15)
at compositeLinkFn (http://localhost/angular/project/scripts/vendor/angular.js:4018:13)
at publicLinkFn (http://localhost/angular/project/scripts/vendor/angular.js:3920:30)
at update (http://localhost/angular/project/scripts/vendor/angular.js:14202:11) 

现在,我的问题是:有没有办法在 .js 文件中找到发生错误的行?
我在引发异常的 angular.js 文件中得到行号,但文件太多
可能会发生错误。

我尝试过 AngularJS Batarang,但这更多是为了调试语义而不是语法错误。

谢谢。

最佳答案

如果您链接到会导致此错误的 js 文件会更容易。

来自 angular.js 源代码,https://ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular.js
实例化 Controller 看起来有问题。

这是导致断言失败的行:

/**
 * @ngdoc function
 * @name ng.$controller
 * @requires $injector
 *
 * @param {Function|string} constructor If called with a function then it's considered to be the
 *    controller constructor function. Otherwise it's considered to be a string which is used
 *    to retrieve the controller constructor using the following steps:
 *
 *    * check if a controller with given name is registered via `$controllerProvider`
 *    * check if evaluating the string on the current scope returns a constructor
 *    * check `window[constructor]` on the global `window` object
 *
 * @param {Object} locals Injection locals for Controller.
 * @return {Object} Instance of given controller.
 *
 * @description
 * `$controller` service is responsible for instantiating controllers.
 *
 * It's just a simple call to {@link AUTO.$injector $injector}, but extracted into
 * a service, so that one can override this service with {@link https://gist.github.com/1649788
 * BC version}.
 */
return function(constructor, locals) {
  if(isString(constructor)) {
    var name = constructor;
    constructor = controllers.hasOwnProperty(name)
        ? controllers[name]
        : getter(locals.$scope, name, true) || getter($window, name, true);

======> assertArgFn(constructor, name, true);
}
  return $injector.instantiate(constructor, locals);
};

无法找到 Controller 的构造函数。

关于debugging - 在 AngularJS 应用程序中查找错误行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17380404/

相关文章:

java - Android 应用程序添加图像后无法启动

c# - 为什么 Visual Studio Debugger 不枚举 BitArray 并显示结果?

debugging - 在 Chrome 的调试器中暂停?

javascript - 在 Javascript 中查找请求 URL

javascript - AngularJS ng-click 创建子范围,但在后续 ng-click 后推送到主范围

angularjs - AngularJS 中的 401 未经授权的错误处理

javascript - JSLINT 关于条件表达式的样式或错误的警告

angularjs - Bootstrap Modal 内的 Blueimp Gallery 未正确垂直对齐

javascript - bootstrap-angular 模态对话框 : can not return value from select

javascript - 如何使用表单数据打印值?