Angularjs,无法运行角度js应用程序

时间:2014-09-18 05:16:31

标签: angularjs angular-ui-bootstrap

我的angularjs应用程序运行良好,直到我最近做了一些更改。从那时起,我收到以下错误(取自Firebug)。我不知道代码的哪一部分导致了这个错误。所以我恢复了我的更改,即便如此我也遇到了同样的错误。

从这个错误堆栈跟踪中,有没有可能让我知道我的角度js代码的哪一部分导致了这个问题?由于我的应用程序很大,我不知道代码的哪一部分可供您参考,而不知道代码的哪一部分导致了这个错误。

在这个错误堆栈跟踪中,我甚至找不到我在angularjs应用程序中创建的函数名称,对象名称等的单个引用。此处的所有行引用仅显示Angular.js文件的行号。任何人都可以指导我,我怎么知道我的angularjs代码的哪一部分导致了这个错误?

Error: node is undefined compositeLinkFn@http://localhost/dashboard2/js/d3angular/angular.js:5989:13 compositeLinkFn@http://localhost/dashboard2/js/d3angular/angular.js:5989:13 nodeLinkFn@http://localhost/dashboard2/js/d3angular/angular.js:6573:1 compositeLinkFn@http://localhost/dashboard2/js/d3angular/angular.js:5986:15 compositeLinkFn@http://localhost/dashboard2/js/d3angular/angular.js:5989:13 publicLinkFn@http://localhost/dashboard2/js/d3angular/angular.js:5891:30 bootstrap/doBootstrap/</<@http://localhost/dashboard2/js/d3angular/angular.js:1384:11 $RootScopeProvider/this.$get</Scope.prototype.$eval@http://localhost/dashboard2/js/d3angular/angular.js:12412:16 $RootScopeProvider/this.$get</Scope.prototype.$apply@http://localhost/dashboard2/js/d3angular/angular.js:12510:18 bootstrap/doBootstrap/<@http://localhost/dashboard2/js/d3angular/angular.js:1382:9 invoke@http://localhost/dashboard2/js/d3angular/angular.js:3869:14 bootstrap/doBootstrap@http://localhost/dashboard2/js/d3angular/angular.js:1380:1 bootstrap@http://localhost/dashboard2/js/d3angular/angular.js:1394:1 angularInit@http://localhost/dashboard2/js/d3angular/angular.js:1307:5 @http://localhost/dashboard2/js/d3angular/angular.js:21459:5 trigger@http://localhost/dashboard2/js/d3angular/angular.js:2509:7 createEventHandler/eventHandler/<@http://localhost/dashboard2/js/d3angular/angular.js:2780:7 forEach@http://localhost/dashboard2/js/d3angular/angular.js:330:11 createEventHandler/eventHandler@http://localhost/dashboard2/js/d3angular/angular.js:2779:5
consoleLog/<()angular.js (line 9778)
$ExceptionHandlerProvider/this.$get</<(exception=
TypeError: node is undefined


childLinkFn(scope, node.childNodes, undefined, boundTranscludeFn);

, cause=undefined)angular.js (line 7216)
$RootScopeProvider/this.$get</Scope.prototype.$apply()angular.js (line 12512)
bootstrap/doBootstrap/<(scope=Scope { $id="002", $$childTail=Scope, $$childHead=Scope, more...}, element=Object[html.ng-scope], compile=compile($compileNodes, transcludeFn, maxPriority, ignoreDirective, previousCompileContext), injector=Object { invoke=invoke(), instantiate=instantiate(), get=getService(), more...}, animate=Object { enter=function(), leave=function(), move=function(), more...})angular.js (line 1382)
invoke(fn=function(scope, element, compile, injector, animate), self=undefined, locals=undefined)angular.js (line 3869)
bootstrap/doBootstrap()angular.js (line 1380)
bootstrap(element=Object[html.ng-scope], modules=["ng", ["$provide", function($provide)], "myApp"])angular.js (line 1394)
angularInit(element=Document testDashboard.do, bootstrap=bootstrap(element, modules))angular.js (line 1307)
angular.js()angular.js (line 21459)
trigger()angular.js (line 2509)
createEventHandler/eventHandler/<(fn=trigger())angular.js (line 2780)
forEach(obj=Object { 0=trigger()}, iterator=function(fn), context=undefined)angular.js (line 330)
createEventHandler/eventHandler(event=DOMContentLoaded , type=undefined)angular.js (line 2779)


return logFn.apply(console, args);

以下是我在控制器中使用并编译它们的一些模板。

var template = ' <div class="table-container"> <smart-table  config="globalConfig" columns="columnCollection" rows="rowCollection"></smart-table>   </div> ';


                        angular.element(
                                        document.querySelector('.snap-content'))
                                .append($compile(template)($scope));



var template = ' <div class="col"> '
                        + ' <p class="graphtitle"> NetSpend Over Time </p> <nvd3 id = "chart3" options="netspendovertime_options" data="netspendovertime_data"></nvd3>   </div>';


                    angular
                            .element(
                                    document.querySelector('.snap-content'))
                            .append($compile(template)($scope));

在编译每个模板之前,我删除了大多数现有的模板DOM元素,如下所示。这种方法有什么不对吗?

// Remove the previously plotted graphs
                    var charts = angular.element(document.body)
                            .find('nvd3')
                    var cntGraphs = charts.length;

                    if (cntGraphs) {
                        while (cntGraphs > 0) {
                            console.log(charts[cntGraphs - 1].parentNode.remove())
                            charts[cntGraphs - 1].remove();
                            cntGraphs = cntGraphs - 1;
                        }

                    }

                    // Remove the previous Titles
                    var tiltles = angular.element(document.body).find('p')
                    var cntTiltles = tiltles.length;

                    if (cntTiltles) {
                        while (cntTiltles > 0) {
                            tiltles[cntTiltles - 1].remove();
                            cntTiltles = cntTiltles - 1;
                        }

                    }

                    // Remove Welcome Images
                    var images = angular.element(document.body).find('img')
                    var cntImages = images.length;

                    if (cntImages) {
                        while (cntImages > 0) {
                            images[cntImages - 1].remove();
                            cntImages = cntImages - 1;
                        }

                    }

                    // Remove All Smart Tables
                    var smartTlbs = angular.element(document.querySelector('.smart-table'))

                    var cntsmartTlbs = smartTlbs.length;

                    if (cntsmartTlbs) {
                        while (cntsmartTlbs > 0) {
                            smartTlbs[cntsmartTlbs - 1].remove();
                            cntsmartTlbs = cntsmartTlbs - 1;
                        }

                    }

1 个答案:

答案 0 :(得分:0)

在浪费了足够的时间之后,小想法来检查chrome中的应用程序。然后在chrome中我得到了完整的堆栈跟踪,我不知道为什么firebug错过了这个信息。从$ scope.allNeedsMet触发的根问题(与underscore.js有关的一些事情)。

根据这些经验,我建议开发人员尝试使用不同的浏览器来处理错误日志,这样可以在这类问题上节省很多时间。

 ReferenceError: _ is not defined
        at Scope.$scope.allNeedsMet (http://localhost/dashboard2/js/controllers.js:160:22)
        at Object.get (http://localhost/dashboard2/js/d3angular/angular.js:10567:21)
        at Scope.$digest (http://localhost/dashboard2/js/d3angular/angular.js:12243:40)
        at Scope.$apply (http://localhost/dashboard2/js/d3angular/angular.js:12516:24)
        at http://localhost/dashboard2/js/d3angular/angular.js:1382:15
        at Object.invoke (http://localhost/dashboard2/js/d3angular/angular.js:3869:17)
        at doBootstrap (http://localhost/dashboard2/js/d3angular/angular.js:1380:14)
        at bootstrap (http://localhost/dashboard2/js/d3angular/angular.js:1394:12)
        at angularInit (http://localhost/dashboard2/js/d3angular/angular.js:1307:5)
        at http://localhost/dashboard2/js/d3angular/angular.js:21459:5 angular.js:9778(anonymous function) angular.js:9778(anonymous function) 
angular.js:7216Scope.$digest angular.js:12270Scope.$apply angular.js:12516(anonymous function)
 angular.js:1382invoke angular.js:3869doBootstrap angular.js:1380bootstrap angular.js:1394angularInit 
angular.js:1307(anonymous function) angular.js:21459trigger angular.js:2509(anonymous function) angular.js:2780forEach angular.js:330eventHandler