[英]Uncaught ReferenceError: angular is not defined app.js
I've searched high and low for an answer to this, but every instance of this problem seems to be fairly unique. 我一直在寻找答案,但是这个问题的每个实例似乎都是相当独特的。 Perhaps a couple extra sets of eyes can help shed some light on this.
也许有几双额外的眼睛可以帮助您对此有所了解。
I'm receiving an error in my console: 我在控制台中收到一个错误:
app.js:23 Uncaught ReferenceError: angular is not defined
app.js:23未捕获的ReferenceError:未定义角度
My angular application is working just fine, but this error continues to persist despite what I do. 我的角度应用程序运行正常,但是尽管我这样做,该错误仍然持续存在。 I think the error came about when I restructured my code to follow a style guide written by Todd Motto.
我认为,当我按照托德·莫托(Todd Motto)编写的样式指南对代码进行重组时,就会发生错误。 In any event, my app.js is as follows:
无论如何,我的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);
})();
My dependencies are as follows: 我的依赖关系如下:
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')
Through trial and error I've omitted each dependency one at a time. 通过反复试验,我一次省略了每个依赖项。 I've tried rearranging the order in which each dependency is loaded and I've even tried rearranging the order in which each of my application specific files are listed, but to no avail.
我尝试重新排列每个依赖项的加载顺序,甚至尝试重新排列列出每个应用程序特定文件的顺序,但无济于事。
Any thoughts on this? 有什么想法吗?
Thanks to @JJJ 感谢@JJJ
"Well you're loading app.js twice: once in the head before Angular has been loaded, and second time in the body after Angular. The first script throws an error but the app works because it runs without error the second time it's loaded:" “好吧,您两次加载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.