0x800a1391 - JavaScript运行时错误:' angular'未定义

时间:2016-12-24 11:42:54

标签: javascript angularjs

我的controller.js有以下代码:

  var myController = angular.module('myApp.controllers', [])

My Services.js包含以下代码:

  angular.module('myApp.services', [])

当我运行我的应用程序时,代码" var myController = angular.module(' myApp.controllers',[])"给了我以下例外: 0x800a1391 - JavaScript运行时错误:' angular'未定义。

谁能告诉我出了什么问题?我们将不胜感激您的帮助:)

顺便说一句,这是我的网络应用程序的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>
&#13;
&#13;
&#13;

2 个答案:

答案 0 :(得分:2)

构建角度应用程序的错误方法 这就是您需要定义模块的方法

var app = angular.module('myApp',[])

这是您需要在controller.js中添加控制器的方法 由于您已经定义了模块,因此无需提供依赖性

    var app = angular.module('myApp')
app.controller('myController',function(){
// Here is your controller content
})

以下是您需要在service.js

中添加服务的方法
var app = angular.module('myApp')
app.service('myService',function(){
// Here is your service content  (this.method);
})

您的代码会给您错误,因为您已经将模块定义了2次,即定义了它的依赖关系[]

答案 1 :(得分:0)

在controller.js上,尝试引用angular.js脚本。

只需将angular.js拖到controller.js文件即可。您的代码将如下所示。

/// <reference path="../../../scripts/angular.js" />

在您的html代码上。包括angular.js并将其放入第一层,然后添加controller.js否则您的代码将无法正常工作。

<script src="scripts/angular.js"></script>
<script src="scripts/controller.js"></script>