【问题标题】:Angular.js only loading half the timesAngular.js 只加载一半的时间
【发布时间】:2014-09-28 13:51:42
【问题描述】:

我遇到了 Angular 应用程序的问题。我正在使用凉亭。当我启动服务器时,有时会收到此错误:

未捕获的错误:[$injector:modulerr] 无法实例化模块 myApp,原因如下: 错误:[$injector:modulerr] 无法实例化模块 ui.router 由于: 错误:[$injector:nomod] 模块“ui.router”不可用!你要么拼错了模块......2)

然后我有时会收到此错误:

Uncaught SyntaxError: Unexpected identifier angular.js:573

Uncaught TypeError: Cannot read property 'module' of undefined angular-route.js:24

Uncaught SyntaxError: Unexpected token ILLEGAL angular-ui-router.js:455

Uncaught ReferenceError: angular is not defined ui-bootstrap-tpls-0.11.0.js:8

Uncaught ReferenceError: angular is not defined app.js:4

未捕获的 ReferenceError:未定义角度

有时 css 也不会完全加载,但不会出现控制台错误。其他时候它工作得很好。

这是我的代码设置

<body ng-app="myApp" class="ng-scope">
<div>
  <div ui-view>
  </div>
</div>

  <script src="bower_components/angular/angular.js"></script>
  <script src="bower_components/angular-route/angular-route.js"></script>
  <script src="bower_components/angular-ui-router/release/angular-ui-router.js"></script>
  <script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

  <script src="//angular-ui.github.io/bootstrap/ui-bootstrap-tpls-0.11.0.js"></script> 
  <script src="js/app.js"></script>
  <script src="js/services.js"></script>
  <script src="js/controllers.js"></script>
  <script src="js/filters.js"></script>
  <script src="js/directives.js"></script>
  <script src="js/create.js"></script>
  <script src="js/view.js"></script>
  <script src="js/header.js"></script>
  <script src="js/form-service.js"></script>
  <script src="js/form-directive.js"></script>
  <script src="js/field-directive.js"></script>
  <script src="js/jquery.dcjqaccordion.2.7.js"></script>

</body>

这是我的 app.js 应用所在的地方

var myApp = angular.module('myApp', [

  'ui.bootstrap.tabs',
  'ui.bootstrap.accordion',
  'ui.bootstrap.collapse',
  /*
  '$strap.directives',
  */
  'ui.router',
  'myApp.filters',
  'myApp.services',
  'myApp.directives',
  'myApp.controllers'


]);

不太清楚该怎么做。我认为加载 angular 然后在延迟时间后加载其他脚本会解决它,但那是行不通的。

【问题讨论】:

  • 如果你在head 中包含你的javascript src 而不是body ??
  • 查看开发工具的网络选项卡,查看文件是否正确返回。另外,建议在 angularjs 之前包含 jquery。

标签: javascript jquery node.js angularjs twitter-bootstrap


【解决方案1】:

您的问题是没有使用 .js 文件的绝对 URL。在每条路径前包含一个/,它应该可以解决您的问题。例如更改:

    <script src="bower_components/angular/angular.js"></script>
  <script src="bower_components/angular-route/angular-route.js"></script>
  <script src="bower_components/angular-ui-router/release/angular-ui-router.js">

<script src="/bower_components/angular/angular.js"></script>
  <script src="/bower_components/angular-route/angular-route.js"></script>
  <script src="/bower_components/angular-ui-router/release/angular-ui-router.js">

对所有文件执行此操作。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-11-04
    • 1970-01-01
    • 2012-06-09
    • 1970-01-01
    相关资源
    最近更新 更多