模板 – AngularJS Karma Ng-html2js =>无法实例化模块… htm
我不能使Karma工作的指令有外部模板。
这里是我的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' ... 在spec文件中: describe('Loading directive',function() { ... beforeEach(module('/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文件是正确的,但不是由karma加载… 此外,如果我使用–log级调试,这里是与模板相关的行:
我缺少什么? 谢谢,
问题可能是在文件节中指定的相对路径被扩展为完整的。
类似于directives / loading / templates / loading.html => /home/joe/project/angular-app/directives/loading/templates/loading.html …然后,模板注册他们的完整路径。 解决方案是配置ng-html2js预处理器以删除模板路径的绝对部分。例如,在karma.conf.js文件中添加stripPrefix指令,如下所示: ngHtml2JsPreprocessor: { // strip this from the file path stripPrefix: '.*/project/angular-app/' prependPrefix: '/app/' } 注意,stripPrefix是一个regexp。 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |