[英]0x800a1391 - JavaScript runtime error: 'angular' is undefined
my controller.js has the following code: 我的controller.js具有以下代码:
var myController = angular.module('myApp.controllers', [])
My Services.js has the following code: 我的Services.js具有以下代码:
angular.module('myApp.services', [])
When I run my application, the code "var myController = angular.module('myApp.controllers', [])" gives me the following exception: 0x800a1391 - JavaScript runtime error: 'angular' is undefined. 当我运行应用程序时,代码“ var myController = angular.module('myApp.controllers',[])”给我以下异常:0x800a1391-JavaScript运行时错误:“ angular”未定义。
Can anyone please tell me what goes wrong? 谁能告诉我哪里出了问题? Your help will be appreciated :) 您的帮助将不胜感激:)
Btw, here is the html code of my web app 顺便说一句,这是我的网络应用程序的html代码
<!DOCTYPE HTML> <html lang="en"> <head> <meta charset="UTF-8"> <title>PathFinding.js</title> <link rel="stylesheet" href="./css/style.css" /> <link rel="stylesheet" href="./lib/themes/jquery.ui.all.css" /> <script src="./js/angular.js"></script> <script type="text/javascript" src="path/to/bower_components/pathfinding/pathfinding-browser.min.js"></script> <script type="text/javascript" src="./lib/raphael-min.js"></script> <script type="text/javascript" src="./lib/es5-shim.min.js"></script> <script type="text/javascript" src="./lib/jquery-1.7.2.min.js"></script> <script type="text/javascript" src="./lib/state-machine.min.js"></script> <script type="text/javascript" src="./lib/async.min.js"></script> <script type="text/javascript" src="./lib/ui/jquery.ui.core.min.js"></script> <script type="text/javascript" src="./lib/ui/jquery.ui.widget.min.js"></script> <script type="text/javascript" src="./lib/ui/jquery.ui.mouse.min.js"></script> <script type="text/javascript" src="./lib/ui/jquery.ui.draggable.min.js"></script> <script type="text/javascript" src="./lib/ui/jquery.ui.accordion.min.js"></script> <script type="text/javascript" src="./lib/ui/jquery.ui.slider.min.js"></script> <script type="text/javascript" src="./lib/pathfinding-browser.min.js"></script> <script type="text/javascript" src="./js/view.js"></script> <script type="text/javascript" src="./js/controller.js"></script> <script type="text/javascript" src="./js/Services.js"></script> <script type="text/javascript" src="./js/mainApp.js"></script> <script type="text/javascript" src="./js/panel.js"></script> <script type="text/javascript" src="./js/main.js"></script> </head> <body> <ion-modal-view> <ion-content> <ion-scroll zooming="true" overflow-scroll="false" direction="xy" style="width: 100%; height:100%;" scrollbar-x="false" scrollbar-y="false"> <div class="scroll-container" id="draw_area" style="width: 100%; height:100%; background: url('PathFindingMap.png') no-repeat "> </div> </ion-scroll> </ion-content> </ion-modal-view> <button style="margin-bottom:10px;margin-left:30px;margin-right:30px;" id="button1" class="control_button" type="button">Search!</button> <div style="visibility: hidden;" id="algorithm_panel" class="panel right_panel"> <div class="accordion"> <h3 id="astar_header"></h3> <div id="astar_section" class="finder_section"> </div> </div> </div> <div style="visibility: hidden;" id="play_panel" class="panel right_panel"> </div> <div id="stats"></div> </body> </html>
Wrong approach of building your angular app This is how you need to define your module 构建角度应用程序的方法错误这就是定义模块的方式
var app = angular.module('myApp',[])
This is how you need to add your controller in your controller.js As you have already define your module,no need to give dependency 这就是您需要在controller.js中添加控制器的方式。由于已经定义了模块,因此无需给出依赖关系
var app = angular.module('myApp')
app.controller('myController',function(){
// Here is your controller content
})
Here is how you need to add your service in service.js 这是您需要在service.js中添加服务的方式
var app = angular.module('myApp')
app.service('myService',function(){
// Here is your service content (this.method);
})
Your code gives you error because you have defined your module 2 times, ie defining its dependency []
您的代码给您错误,因为您已经定义了2次模块,即定义了模块的依赖项[]
On your controller.js try to reference the angular.js script. 在您的controller.js上尝试引用angular.js脚本。
Simply drag the angular.js to you controller.js file. 只需将angular.js拖动到controller.js文件即可。 You code will look like this. 您的代码将如下所示。
/// <reference path="../../../scripts/angular.js" />
On your html code. 在您的html代码上。 Include the angular.js and put it into first hierarchy then add your controller.js or else your code will not work. 包括angular.js并将其放入第一层,然后添加controller.js否则您的代码将无法工作。
<script src="scripts/angular.js"></script>
<script src="scripts/controller.js"></script>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.