【问题标题】:Angular module not available after grunt build even with ng-annotate即使使用 ng-annotate,在 grunt 构建后 Angular 模块也不可用
【发布时间】:2016-06-01 10:24:30
【问题描述】:

我正在使用 Yeoman 角度发生器。我创建了 Angular 模块并尝试将其加载到应用程序中。 Grunt 使用的是 ng-annotate,供应商脚本(模块所在的位置)是在应用脚本之前加载的,所以我不知道是什么问题。

这是压缩后的 index.html

<!doctype html> <html> <head> <meta charset="utf-8"> <title></title> <meta name="description" content=""> <meta name="viewport" content="width=device-width"> <!-- Place favicon.ico and apple-touch-icon.png in the root directory --> <link rel="stylesheet" href="styles/vendor.20fdc362.css"> <link rel="stylesheet" href="styles/main.16c86e60.css"> </head> <body ng-app="strauiApp"> <!--[if lte IE 8]>
  <p class="browsehappy">You are using an <strong>outdated</strong> browser. Please <a href="http://browsehappy.com/">upgrade your browser</a> to improve your experience.</p>
<![endif]--> <div ui-view></div> <script src="scripts/vendor.c9b57eb5.js"></script> <script src="scripts/scripts.7ce0b4a1.js"></script> </body> </html>

这是注册模块的供应商文件的一部分

function(){"use strict";angular.module("streamlineCore",["configs","ngResource","ui.router","ngMessages","toastr","angular-loading-bar","ipCookie"]).config ...

这是脚本文件的开始

!function(){"use strict";angular.module("strauiApp",["streamlineCore","ui.bootstrap"])}(),

错误是

Uncaught Error: [$injector:modulerr] Failed to instantiate module strauiApp due to: Error: [$injector:modulerr] Failed to instantiate module streamlineCore due to: Error: [$injector:nomod] Module 'streamlineCore' 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.

这里有什么问题?缺少什么?

【问题讨论】:

    标签: angularjs gruntjs yeoman ng-annotate


    【解决方案1】:

    您确定 streamlineCore 模块是在 strauiApp 模块之前插入 scripts/scripts.7ce0b4a1.js 中的吗?

    【讨论】:

    • 它被插入到供应商文件中。
    • 当我将模块移动到脚本文件时,它看起来已加载,但现在我收到“无法实例化模块 ngResource”错误。所以似乎无法加载供应商文件中的所有模块。
    • 文件中模块的顺序很重要。确保在依赖模块之前加载每个模块的依赖项。
    【解决方案2】:

    是 bootstrap js 导致了这个问题。这个 js 是由 grunt-wiredep 自动添加的。

    【讨论】:

      猜你喜欢
      • 2017-01-16
      • 1970-01-01
      • 1970-01-01
      • 2017-09-16
      • 1970-01-01
      • 2020-01-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多