javascript - gulp-angular-templatecache 模块不可用

标签 javascript angularjs gulp angular-templatecache

我正在使用gulp-angular-templacache。 我的任务应该创建一个名为 templates 的模块,并将其添加为我的 app 模块的依赖项:

配置:

templateCache: {
            file: 'tempaltes.js',
            options: {
                    module: 'templates',
                    standalone: true,
                    root: 'app/'
            }
        }

应用程序模块:

var App = angular.module('app', [
    'templates']);

gulp 任务:

gulp.task('templatecache', ['clean-code'], function() {
log('Creating AngularJS $templateCache');

return gulp
    .src(config.htmltemplates)
    .pipe($.minifyHtml({empty: true}))
    .pipe($.angularTemplatecache(
        config.templateCache.file,
        config.templateCache.options
    ))
    .pipe(gulp.dest(config.temp));

});

但是,当我尝试运行此程序时,我总是收到该错误消息:

Uncaught Error: [$injector:nomod] Module 'templates' 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.

我尝试使 templatescache 也不再独立并删除依赖项,但没有成功...... 我该怎么办??

最佳答案

似乎您正在加载 template.js,在模块 app 定义之后。您可以在 Angular app 文件

之前加载该文件

或者,不要定义独立模块。

配置

templateCache: {
    file: 'tempaltes.js',
    options: {
            module: 'templates',
            standalone: false,
            root: 'app/'
    }
}

Angualr

//Define the module
angular.module('templates', []);
var App = angular.module('app', ['templates']);

关于javascript - gulp-angular-templatecache 模块不可用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43292821/

相关文章:

javascript - 如果 Angular 正在做......从 Selenium 中检测东西

javascript - 在 highcharts 的 Y 轴上显示带下划线的标签文本

javascript - Mongoose 更新子文档的子文档

javascript - 模态表单上的 jQuery Submit() vc click()

javascript - 如何处理每个时刻状态下的动画滚动事件?

php - angularjs bool 值 php 后回调

node.js - 不使用回调时未定义结果。 Nodejs、Express 和 SQL Server Express

javascript - Gulp 缩小所有 css/js 并移动到具有相同结构的文件夹?

javascript - 在生产构建期间从 bundle 中删除 JavaScript 代码

javascript - 如何在文本框下居中jquery datepicker