Angular.js:错误:模块“MyApp”不可用

时间:2015-10-22 02:05:32

标签: javascript html angularjs module

我想在我的机器上本地使用this plunk。但是,当我使用本地Python服务器或Off运行它时,我不断收到以下错误:

http-server

我的 html文件如下所示:

Uncaught Error: [$injector:modulerr] Failed to instantiate module myApp due     to:
    Error: [$injector:nomod] Module 'myApp' is not available! You either     misspelled the module name or forgot to load it. If registering a module ensure      that you specify the dependencies as the second argument.

main.js 文件如下所示:

<!DOCTYPE html>
<html ng-app="myApp">

  <head lang="en">
    <meta charset="utf-8" />
    <title>Custom Plunker</title>
    <script scr="main.js"></script>
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.js"></script>
    <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.0/angular.js"></script>
    <script src="http://cdnjs.cloudflare.com/ajax/libs/PapaParse/4.1.1/papaparse.min.js"></script>
    <script src="http://cdnjs.cloudflare.com/ajax/libs/angular-file-upload/1.1.5/angular-file-upload.min.js"></script>
    <link rel="stylesheet" href="main.css">
  </head>

  <body ng-controller="MyCtrl">
    <h1>CSV</h1>
    <div>
      <input type="checkbox" ng-model="append">
      Append to existing on drag & drop
    </div>
    <div class="drop-container" nv-file-drop nv-file-over uploader="uploader">
      <textarea ng-model="csv" placeholder="Enter your CSV here, or drag/drop a CSV file"></textarea>
    </div>

    <h1>D3 Flare JSON</h1>
    <div>
      <input type="checkbox" ng-model="compact"> Compact
    </div>
    <div>
      <input type="text" ng-model="tags.parent" placeholder="parent tag">
      <input type="text" ng-model="tags.children" placeholder="children tag">
      <input type="text" ng-model="tags.leaf" placeholder="leaf tag">
      <input type="text" ng-model="tags.size" placeholder="size tag">
    </div>
    <textarea readonly ng-model="json"></textarea>
  </body>

</html>

我不明白我做错了什么。我已经搜索了类似的错误消息,但我发现的任何内容都无法帮助我解决问题。

3 个答案:

答案 0 :(得分:2)

您在angularjs文件之前加载脚本文件,这就是您收到此错误的原因。 因此,在“angular.js”文件之后添加“main.js”文件。

<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.0/angular.js"></script>
<script scr="main.js"></script>

答案 1 :(得分:0)

我相信这是因为您在加载Angular之前加载了main.js。尝试将脚本放在脚本定义的末尾:

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.0/angular.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/PapaParse/4.1.1/papaparse.min.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/angular-file-upload/1.1.5/angular-file-upload.min.js"></script>
<script scr="main.js"></script>

答案 2 :(得分:0)

哦,解决了!事实证明,main.js中的以下几行引起了麻烦:

CSV to D3 Flare JSON converter in AngularJSPreview Edit Code
index.html
main.js
main.css
main.js

我从main.js删除了它们,现在它可以了 - yuhuu! :)