AngularJS + +噶吴-html2js =>无法实例化模块... HTML [英] AngularJS + Karma + Ng-html2js => Failed to instantiate module ...html

查看:256
本文介绍了AngularJS + +噶吴-html2js =>无法实例化模块... HTML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不能让噶工作具有外部模板指令。

下面是我的人缘配置文件:

preprocessors:{
    指令/加载/模板/ loading.html':'NG-html2js
},文件:
    ...
    指令/加载/模板/ loading.html',
]ngHtml2Js preprocessor:{
    prePEND preFIX:'/应用/'
},

在指令文件:

...
templateUrl:/app/directives/loading/templates/loading.html
...

在规范文件:

描述(正在载入指令',函数(){
    ...
    beforeEach(模块('/应用程序/指令/加载/模板/ loading.html'));
    ...
});

我收到以下错误:


  

未能实例由于模块/app/directives/loading/templates/loading.html:
  错误:无模块:/app/directives/loading/templates/loading.html


如果我修改的源$ C ​​$ C人缘-NG-html2js- preprocessor要打印的结果
生成的文件,我得到:

angular.module('/应用程序/指令/加载/模板/ loading.html',[])。运行(功能($ templateCache){
    $ templateCache.put('/应用程序/指令/加载/模板/ loading.html',
        '< D​​IV NG隐藏=hideLoading级=loading_panel> \\ N'+
        '< D​​IV CLASS =中心> \\ N'+
        '< D​​IV CLASS =内容> \\ N'+
        '<跨度NG-transclude>< / SPAN> \\ N'+
        '<画布宽度=32高度=32>< /帆布> \\ N'+
        '< / DIV> \\ N'+
        '< / DIV> \\ N'+
    '< / DIV>');
});

如此看来,生成的JS文件是正确的,但不是因果报应加载中...

另外,如果我用--log级调试,这里涉及到模板中的行:


  

DEBUG [preprocessor.html2js]:处理/home/rightink/public_html/bo2/master/web/app/directives/loading/templates/loading.html


  
  

DEBUG [观察家]:解决文件:

/correct/path/to/the/app/directives/loading/templates/loading.html.js


我缺少的东西吗?

谢谢,


解决方案

您可以有pre-处理器缓存你的模板模块,然后可以前你的测试包括:

karma.conf.js

 文件:
  ...
  应用程序/ ** / *。HTML
]preprocessors:{
  '应用程序/ ** / * HTML':'NG-html2js']
},ngHtml2Js preprocessor:{
   MODULENAME:'模板'
},

指令文件

  ...
templateUrl:应用程序/路径到你的/ template.html',
...

规范文件

 描述(我的指令',函数(){  beforeEach(模块('模板'));
  ...
});

I can't make Karma working for directives that have external templates.

Here is my karma configuration file :

preprocessors: {
    'directives/loading/templates/loading.html': 'ng-html2js'
},

files: [
    ...
    'directives/loading/templates/loading.html',
]

ngHtml2JsPreprocessor: {
    prependPrefix: '/app/'
},

In the directive file :

...
templateUrl: '/app/directives/loading/templates/loading.html'
...

In the spec file :

describe('Loading directive', function() {
    ...
    beforeEach(module('/app/directives/loading/templates/loading.html'));
    ...
});

I get the following error :

Failed to instantiate module /app/directives/loading/templates/loading.html due to: Error: No module: /app/directives/loading/templates/loading.html

If I modify the source code of the karma-ng-html2js-preprocessor to print the result of the generated file, I get :

angular.module('/app/directives/loading/templates/loading.html', []).run(function($templateCache) {
    $templateCache.put('/app/directives/loading/templates/loading.html',
        '<div ng-hide="hideLoading" class="loading_panel">\n' +
        '   <div class="center">\n' +
        '       <div class="content">\n' +
        '           <span ng-transclude></span>\n' +
        '           <canvas width="32" height="32"></canvas>\n' +
        '       </div>\n' +
        '   </div>\n' +
    '</div>');
});

So it seems that the generated JS file is correct but not loaded by karma...

Also, if I use --log-level debug, here are the lines related to the template :

DEBUG [preprocessor.html2js]: Processing "/home/rightink/public_html/bo2/master/web/app/directives/loading/templates/loading.html"

DEBUG [watcher]: Resolved files:

      /correct/path/to/the/app/directives/loading/templates/loading.html.js

Am I missing something ?

Thanks,

解决方案

You can have the pre-processor cache your templates to a module, which can then be included prior to your tests:

karma.conf.js

files: [
  ...
  'app/**/*.html'
],

preprocessors: {
  'app/**/*.html': ['ng-html2js']
},

ngHtml2JsPreprocessor: {
   moduleName: 'templates'
},

directive file

...
templateUrl: 'app/path-to-your/template.html',
...

spec file

describe('My directive', function() {

  beforeEach(module('templates'));
  ...
});

这篇关于AngularJS + +噶吴-html2js =&GT;无法实例化模块... HTML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆