簡體   English   中英

未捕獲的ReferenceError:未定義角度app.js

[英]Uncaught ReferenceError: angular is not defined app.js

我一直在尋找答案,但是這個問題的每個實例似乎都是相當獨特的。 也許有幾雙額外的眼睛可以幫助您對此有所了解。

我在控制台中收到一個錯誤:

app.js:23未捕獲的ReferenceError:未定義角度

我的角度應用程序運行正常,但是盡管我這樣做,該錯誤仍然持續存在。 我認為,當我按照托德·莫托(Todd Motto)編寫的樣式指南對代碼進行重組時,就會發生錯誤。 無論如何,我的app.js如下:

(function() {

function config($routeProvider) {
    $routeProvider
        .when('/', {
            templateUrl: 'partial/main'
        })
        .when('/assignment/:id', {
            templateUrl: 'partial/assignment',
            controller: 'SubmissionController'
        }).otherwise({
            redirectTo: '/'
        });
}
angular
    .module('myApp', ['ngRoute', 'ui.materialize', 'ngAnimate'])
    .config(config);

})();

我的依賴關系如下:

doctype html
html(ng-app="myApp")
  head
    meta(charset="utf-8")
    meta(http-equiv="X-UA-Compatible", content="IE=edge")
    meta(name="viewport", content="width=device-width, initial-scale=1.0, maximum-scale=1.0")

    title= title    

    link(rel='icon', type='image/png', href='favicon.ico')

    // bower:css
    link(rel='stylesheet', href='../bower_components/animate.css/animate.css')
    // endbower

    script(src='js/app.js') styles
    link(rel="stylesheet", href="css/app.css") 
    link(href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet")

  body(ng-controller="AssignmentController")
    block content 

    //- lib js
    // bower:js
    script(src='../bower_components/jquery/dist/jquery.js')
    script(src='../bower_components/angular/angular.js')
    script(src='../bower_components/Materialize/bin/materialize.js')
    script(src='../bower_components/angular-route/angular-route.js')
    script(src='../bower_components/angular-animate/angular-animate.js')
    script(src='../bower_components/angular-materialize/src/angular-materialize.js')
    // endbower  

    //- app js 
    script(src='js/app.js')
    script(src='js/controllers.js')
    script(src='js/services.js')
    script(src='js/directives.js')        
    script(src='//localhost:35729/livereload.js')  

通過反復試驗,我一次省略了每個依賴項。 我嘗試重新排列每個依賴項的加載順序,甚至嘗試重新排列列出每個應用程序特定文件的順序,但無濟於事。

有什么想法嗎?

感謝@JJJ

“好吧,您兩次加載app.js:一次是在Angular加載之前的頭部中,一次是在Angular加載之后的正文中。第一個腳本會引發錯誤,但該應用程序可以正常運行,因為它在第二次加載時便沒有錯誤地運行:“

doctype html
html(ng-app="myApp")
  head
    meta(charset="utf-8")
    meta(http-equiv="X-UA-Compatible", content="IE=edge")
    meta(name="viewport", content="width=device-width, initial-scale=1.0, maximum-scale=1.0")

    title= title    

    link(rel='icon', type='image/png', href='favicon.ico')

    // bower:css
    link(rel='stylesheet', href='../bower_components/animate.css/animate.css')
    // endbower

    // - [FIX] removed: script(src='js/app.js')         
    link(rel="stylesheet", href="css/app.css") 
    link(href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet")

  body(ng-controller="AssignmentController")
    block content 

    //- lib js
    // bower:js
    script(src='../bower_components/jquery/dist/jquery.js')
    script(src='../bower_components/angular/angular.js')
    script(src='../bower_components/Materialize/bin/materialize.js')
    script(src='../bower_components/angular-route/angular-route.js')
    script(src='../bower_components/angular-animate/angular-animate.js')
    script(src='../bower_components/angular-materialize/src/angular-materialize.js')
    // endbower  

    //- app js 
    script(src='js/app.js')
    script(src='js/controllers.js')
    script(src='js/services.js')
    script(src='js/directives.js')        
    script(src='//localhost:35729/livereload.js')  

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM