我不能让 Karma 为具有外部模板的指令工作。
这是我的业力配置文件:
preprocessors: {
'directives/loading/templates/loading.html': 'ng-html2js'
},
files: [
...
'directives/loading/templates/loading.html',
]
ngHtml2JsPreprocessor: {
prependPrefix: '/app/'
},
在指令文件中:
...
templateUrl: '/app/directives/loading/templates/loading.html'
...
在规范文件中:
describe('Loading directive', function() {
...
beforeEach(module('/app/directives/loading/templates/loading.html'));
...
});
我收到以下错误:
无法实例化模块 /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>');
});
所以看起来生成的JS文件是正确的但没有被业力加载......
另外,如果我使用 --log-level 调试,这里是与模板相关的行:
调试 [preprocessor.html2js]:处理“/home/rightink/public_html/bo2/master/web/app/directives/loading/templates/loading.html”
调试 [观察者]:已解决的文件:
/correct/path/to/the/app/directives/loading/templates/loading.html.js
我错过了什么吗?
谢谢,