【问题标题】:Using gulp-angular-templatecache to combine HTML into template.js, getting $injector Module Unavailable error使用 gulp-angular-templatecache 将 HTML 合并到 template.js 中,得到 $injector Module Unavailable 错误
【发布时间】:2015-07-16 02:55:00
【问题描述】:

我正在使用gulp-angular-templatecache 来获取我所有的部分HTML 模板文件并将它们组合成1 个template.js 文件。

我能够完成的第一部分,我可以运行我的 Gulp 任务并创建 templates/templates.js

templates.js:

angular.module("templates").run(["$templateCache", function($templateCache) {$templateCache.put("beta.html","<div class=\"login-container\" ng-controller=\"BetaCtrl as beta\">\n    <section class=\"login-form-block\">\n        <header>\n            <div class=\"tickertags-logo-big\"></div>\n            <h1>Welcome to the TickerTags beta! Enter the email address where your beta invitation was sent below. We will send you an email with your temporary password.</h1>\n        </header>\n\n        <div class=\"login-form\">\n\n            <form name=\"loginForm\" ng-submit=\"beta.beta(credentials)\" novalidate>\n\n                <div class=\"login-alert\" ng-class=\"{ hideLoginMsg: beta.hideMessage == true }\">{{ beta.message }}</div>\n\n                <input type=\"email\"\n                       id=\"email\"\n                       placeholder=\"Email\"\n                       name=\"email\"\n                       ng-model=\"credentials.email\">\n\n                <button type=\"submit\" class=\"login-btn\">Email Password</button>\n            </form>\n\n            <p class=\"terms-of-use-line\">By signing up you agree to our <a href=\"assets/files/tickertags-terms-of-use.pdf\" target=\"_blank\">Terms of Use</a> and <a href=\"assets/files/privacypolicy.pdf\" target=\"_blank\">Privacy Policy</a></p>\n\n        </div>\n    </section>\n</div>\n");

现在我已正确链接到索引中的 templates.js 文件:

<script src="templates/templates.js"></script> <<--
<script src="authentication/authFactory.js"></script>
<script src="help/helpController.js"></script>
etc...

我已经将它包含在主应用模块中:

var app = angular.module('tickertags', [
    'ui.router',
    'templates',  // <--
    'authFactory',
    'betaController',
    'passResetController',
    'loginController',
    'apiFactory',
    'scopeFactory',
    etc...

但仍然出现此错误: https://docs.angularjs.org/error/$injector/nomod?p0=templates

错误:$injector:nomod 模块不可用

关于为什么我会看到这个的想法?

【问题讨论】:

    标签: javascript angularjs templates gulp angularjs-templates


    【解决方案1】:

    因为该模块没有正确声明。

    您需要在应用程序的某处声明模板模块,如下所示:angular.module("templates", []); 或在 gulp 插件中使用 options.standalone = true

    来自文档:

    注意:这个插件默认不会创建一个新的AngularJS模块,而是使用一个叫做模板的模块。如果您想创建一个新模块,请将 options.standalone 设置为 true。

    【讨论】:

    • 谢谢!就是这样 :) 好的,现在是最后一步......弄清楚如何让指令使用新的 template.js 文件。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-01-13
    • 2016-10-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多