小编Vin*_*ent的帖子

AngularJS + Karma + Ng-html2js =>无法实例化模块... html

我无法使Karma适用于具有外部模板的指令.

这是我的业力配置文件:

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

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

ngHtml2JsPreprocessor: {
    prependPrefix: '/app/'
},
Run Code Online (Sandbox Code Playgroud)

在指令文件中:

...
templateUrl: '/app/directives/loading/templates/loading.html'
...
Run Code Online (Sandbox Code Playgroud)

在spec文件中:

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

我收到以下错误:

由于以下原因无法实例化模块/app/directives/loading/templates/loading.html:错误:无模块:/app/directives/loading/templates/loading.html

如果我修改karma-ng-html2js-preprocessor的源代码来打印生成文件的结果,我得到:

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>');
});
Run Code Online (Sandbox Code Playgroud)

所以似乎生成的JS文件是正确的但没有被karma加载......

另外,如果我使用--log-level debug,这里是与模板相关的行:

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
Run Code Online (Sandbox Code Playgroud)

我错过了什么吗?

谢谢,

testing templates directive angularjs karma-runner

26
推荐指数
3
解决办法
1万
查看次数

标签 统计

angularjs ×1

directive ×1

karma-runner ×1

templates ×1

testing ×1