简体   繁体   English

InternalError:太多的递归<div ng-view=“” class=“ng-scope”>

[英]InternalError: too much recursion <div ng-view=“” class=“ng-scope”>

I am new to angularJS . 我是angularJS的新手。 I am stuck on above error.here is my index.html 我被卡在上述错误上。这是我的index.html

<body ng-app="myApp">
    <div ng-view></div>
    <a href="table">click</a>

    <script src="./libs/angular.js"></script>
    <script src="./libs/angular-route.js"></script>
    <script src="./scripts/myscript.js"></script>
</body>

here is my script file 这是我的脚本文件

    var app=angular.module("myApp",['ngRoute']);

app.config(['$routeProvider',function($routeProvider){
    console.log("i am routeprovider");
    $routeProvider.when('/',{
        templateUrl:"index.html"
    }).when('/table',{
        templateUrl:"..//views//firstview.html"
    }).otherwise({
        redirectTo: 'google.com'
    })

}])

after running index.html on my local server i am getting following error in console 在我的本地服务器上运行index.html后,我在控制台中收到以下错误

InternalError: too much recursion Stack trace: [object Object] <div ng-view="" class="ng-scope">

see attached image. 见所附图片。

在此处输入图片说明

please help me sort this issue . 请帮助我解决这个问题。

This error occurs because you've set the templateUrl to index.html which is actually also your parent template. 发生此错误是因为您已将templateUrl设置为index.html,而实际上它也是您的父模板。

When resolving the route '/' angular will inject the template index.html into the container <div ng-view></div> . 解决路径“ /” angular时,会将模板index.html注入到容器<div ng-view></div> The injected template also has the ng-view container. 注入的模板还具有ng-view容器。 So angular will do this over and over again and is stuck in an endless recursion. 因此,角度将一遍又一遍地执行此操作,并陷入无休止的递归中。

You can fix this by defining another partial view for this templateUrl eg defaultview.html. 您可以通过为此templateUrl定义另一个局部视图来解决此问题,例如defaultview.html。

Code

$routeProvider.when('/',{
    templateUrl:"..//views//defaultview.html"
}).when('/table',{
    templateUrl:"..//views//firstview.html"
}).otherwise({
    redirectTo: '/'
})

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM