angularjs
  • mean-stack
  • 2017-07-24 216 views 0 likes 
    0

    當我嘗試從localhost8000加載我的index.html頁面時出現以下錯誤。未捕獲的錯誤角度未在main.js頁面的第2行上定義。未定義未捕獲的錯誤角度未定義

    的Index.html:

    <!DOCTYPE html> 
    <html lang='en' ng-app='App'> 
        <head> 
         <meta charset="utf-8"> 
         <script src = 'angular/angular.js'></script> 
         <script src = 'angular-route/angular-route.js'></script> 
         <script src = 'js/main.js'></script> 
         <title></title> 
        </head> 
        <body> 
         <ng-view></ng-view> <!-- Allows loading of partials--> 
        </body> 
    </html> 
    
    Main.js page: 
    
    // Will handle our ng-routes 
    var app = angular.module('App', ['ngRoute']) 
    
    // Configure the partials 
    app.config(function($routeProvider) { 
        $routeProvider.when('/', { 
         templateUrl: '/partials/_ninjas.html', // Allows us to move around and see all the ninjas 
        }); 
    }); 
    

    是否有錯字的地方在我的代碼,我沒有看到。我仍然參加在線編碼訓練營學習編碼,所以任何提示將不勝感激:)

    回答

    0

    儘量保證角庫加載正確的代碼似乎要被罰款

    <!DOCTYPE html> 
     
    <html lang="en"> 
     
    
     
        <head> 
     
        <meta charset="utf-8" /> 
     
        <title></title> 
     
        <script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.6.5/angular.min.js"></script> 
     
        <script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.6.5/angular-route.js"></script> 
     
        <script src="main.js"></script> 
     
        </head> 
     
    
     
        <body ng-app="App"> 
     
        <ng-view></ng-view> 
     
        <!-- Allows loading of partials--> 
     
        <script> 
     
        var app = angular.module('App', ['ngRoute']) 
     
    
     
    // Configure the partials 
     
    app.config(function($routeProvider) { 
     
        $routeProvider.when('/', { 
     
         template: '<div>Hello</div>', // Allows us to move around and see all the ninjas 
     
        }); 
     
    }); 
     
        </script> 
     
        </body> 
     
    
     
    </html>

    對代碼進行測試

    +0

    那這樣做做的伎倆感謝幫助:) –

    +0

    @DanielMayle你可以標記接受的答案,如果它幫助。 – abdoutelb

    +1

    確定點擊綠色複選標記吧? –

    -1

    該錯誤實現您沒有角加載。

    更換

    <script src = 'angular/angular.js'></script> 
    

    與此:

    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.5/angular.min.js"></script> 
    

    看看它是否工作。

    +0

    的伎倆感謝您的幫助:) –

    相關問題