2016-04-03 50 views
3

在標題中提到的NetBeans錯誤中運行AngularJS應用程序後出現。我看不到堆棧超載的任何點,因爲您看到我只初始化了兩個用於登錄表單處理的變量(我在我的AngularJS冒險開始時)。它可能是一些硬件問題,或者我在這裏做了一些無意識的錯誤?AngularJS - RangeError:'應用程序啓動後超出最大調用堆棧大小

錯誤:

RangeError: Maximum call stack size exceeded 
    at c (public_html/bower_components/angular/angular.min.js:115:232) 
    at http://localhost:8383/LoginJS/bower_components/angular/angular.min.js:115:506 
    at q (public_html/bower_components/angular/angular.min.js:7:355) 
    at Object.error (public_html/bower_components/angular/angular.min.js:115:475) 
    at http://localhost:8383/LoginJS/bower_components/angular/angular.min.js:89:12 
    at ra (public_html/bower_components/angular/angular.min.js:69:475) 
    at xa (public_html/bower_components/angular/angular.min.js:58:270) 
    at xa (public_html/bower_components/angular/angular.min.js:58:402) 
    at ba (public_html/bower_components/angular/angular.min.js:56:264) 
    at A.link (public_html/bower_components/angular-route/angular-route.min.js:7:224) (13:52:05:371 | error) 

app.js

angular.module('myapp', ['ngRoute']).config(function($routeProvider) { 
     $routeProvider 
       .when('/', { 
        templateUrl: 'index.html' 
     }) 
       .when('/dashboard', { 
        templateUrl: 'dashboard.html' 
     }) 
       .otherwise(({ 
        redirectTo: '/' 
     })); 
}); 

loginCtrl.js

angular.module('myapp').controller('loginCtrl', function($scope, $location) { 
    $scope.submit = function() { 
     var username = $scope.username; 
     var password = $scope.password; 

     if($scope.username == 'admin' && $scope.password == 'admin') { 
      $location.path('/dashboard'); 
     } 
    }; 
}) 

的index.html

<html> 
    <head> 
     <title>TODO supply a title</title> 
     <meta charset="UTF-8"> 
     <meta name="viewport" content="width=device-width, initial-scale=1.0"> 
     <script src="bower_components/angular/angular.min.js" type="text/javascript"></script> 
     <script src="bower_components/angular-route/angular-route.min.js" type="text/javascript"></script> 
     <script src="app.js" type="text/javascript"></script> 
     <script src="scripts/controllers/loginCtrl.js" type="text/javascript"></script> 
    </head> 
    <body ng-app="myapp"> 
     <div ng-view></div> 
     <div ng-controller="loginCtrl"> 
      <form action="/" id="login"> 
       Username: <input type="text" name="username" id="username" ng-model="username"><br> 
       Password: <input type="password" name="password" id="password" ng-model="password"><br> 
       <button type="button" ng-click="submit()">Login</button> 
      </form> 
     </div> 
    </body> 
</html> 

dashboard.html

<html> 
    <head> 
     <title>TODO supply a title</title> 
     <meta charset="UTF-8"> 
     <meta name="viewport" content="width=device-width, initial-scale=1.0"> 
     <script src="bower_components/angular/angular.min.js" type="text/javascript"></script> 
     <script src="bower_components/angular-route/angular-route.min.js" type="text/javascript"></script> 
     <script src="app.js" type="text/javascript"></script> 

    </head> 
    <body ng-app="myapp"> 
     <div ng-view></div> 
     some text 
    </body> 
</html> 

回答

4

因爲你加載頁面和負載index.html所有腳本文件'/'路徑,循環加載index.html頁面,這就是爲什麼你得到這個錯誤。

dashboard.html無需再次加載您的腳本文件只是寫你的信息沒有別的。然後您的登錄表單移動到另一個頁面,如login.html,並參考此頁的路徑"/"

喜歡:

路線提供商:

.when('/', { 
     templateUrl: 'login.html' 
}) 

index.html

<body ng-app="myapp"> 
    <h1>Welcome </h1> 
    <div ng-view></div> 
</body> 

login.html

<div ng-controller="loginCtrl"> 
     <form action="/" id="login"> 
      Username: <input type="text" name="username" id="username" ng-model="username"><br> 
      Password: <input type="password" name="password" id="password" ng-model="password"><br> 
      <button type="button" ng-click="submit()">Login</button> 
     </form> 
</div> 

dashboard.html

<div ng-controller="CtrlName"> //ng-controller="CtrlName" if need ctrl and also can use ctrl in route provider 
    <h2> Dashboard page</h2> 
    // all of your information's 
</div> 

它可能會很好地工作

+0

我修改dashboard.html根據您的建議和錯誤沒有消失 –

+0

你有任何功能,做循環參考?並可以嘗試通過將登錄信息轉移到另一個html頁面,如'login.html'和'/''路徑將該頁面作爲'templateUrl'而不是'index.html' @Mike –

+0

更新可能會回答,它應該是工作@Mike –

0

使用腳本控制的方向負載腳本文件再次只寫你的信息沒有別的。然後您的登錄表單移動到另一個頁面,如login.html,並參考此頁的路徑"/"

相關問題