简体   繁体   中英

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

I am new to angularJS . I am stuck on above error.here is my 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

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.

When resolving the route '/' angular will inject the template index.html into the container <div ng-view></div> . The injected template also has the ng-view container. 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.

Code

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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