【问题标题】:gulp-angular-templatecache Module is not availablegulp-angular-templatecache 模块不可用
【发布时间】:2017-04-08 19:00:30
【问题描述】:

我正在使用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));

});

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

未捕获的错误:[$injector:nomod] 模块“模板”不可用!您要么拼错了模块名称,要么忘记加载它。如果注册模块,请确保将依赖项指定为第二个参数。

我试图使模板缓存也不是独立的并删除依赖项但没有成功...... 我该怎么办??

【问题讨论】:

  • 文件的顺序是什么?
  • file: 'tempaltes.js'
  • 我在问脚本标签的顺序

标签: javascript angularjs gulp angular-templatecache


【解决方案1】:

您似乎正在加载 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']);

【讨论】:

  • 刚试过,我得到模块'模板'不可用在我的 index.html 中,我在注入我的应用程序 js 之后注入了 templates.js。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2016-10-19
  • 2015-08-01
  • 2017-01-13
  • 1970-01-01
  • 2017-04-15
  • 2015-10-06
  • 1970-01-01
相关资源
最近更新 更多