AngularJS - RangeError:'在'之后超出最大调用堆栈大小申请开始

时间:2016-04-03 12:03:20

标签: javascript angularjs

在NetBeans中运行AngularJS应用程序后出现标题中提到的错误。我无法看到堆栈重载的任何点,正如您所看到的,我只初始化了两个变量用于登录表单处理(我在AngularJS冒险开始时的i)。这可能是一些硬件问题还是我在这里犯了一些无意识的错误?

错误:

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>

2 个答案:

答案 0 :(得分: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>

它可能会完美地运作

答案 1 :(得分:0)

在方向上使用脚本控件来再次加载脚本文件只需编写您的信息。您的登录表单会移至login.html之类的其他网页,并在此页面中查看路径"/"