我有指令:
angular
.module('app')
.directive('stat24hour', stat24hour);
function stat24hour(req) {
var directive = {
link: link,
template: 'scripts/widgets/templates/stat24Hour.html'
};
return directive;
function link(scope) {
req.option('stats').then(function(data){
scope.stats = data;
});
}
}
我配置 karma 使我的模板 *.html 像模块
(function(module) {
try {
module = angular.module('template');
} catch (e) {
module = angular.module('template', []);
}
module.run(function($templateCache) {
$templateCache.put('scripts/widgets/templates/stat24Hour.html','Here HTML');
});
})();
但是当我尝试使用时
angular.module('template');
inject(function($compile, $rootScope){
compile = $compile;
scope = $rootScope.$new();
var element = angular.element('div stat24hour');
var compiledElement = compile(element)(scope);
console.log(compiledElement);
});
编译返回 html,不使用指令模板。 需要修复什么才能使其正常工作?
最佳答案
您的指令中有 template: '..',加载外部资源时应使用 templateUrl。 template:表示静态字符串作为模板
关于javascript - 如何正确使用 karma-ng-html2js-preprocessor?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31816021/