不要在Jasmine Karma Angular中使用$compile
Don't work $compile in Jasmine Karma Angular
(function () {
'use strict';
angular
.module('app.widgets')
.directive('analiticsHere', analitics);
function analitics() {
var directive = {
template: '<div>hello world</div>'
};
return directive;
}
})();
创建简单指令。我试着测试一下。
inject(function($compile, $rootScope, $templateCache){
compile = $compile;
scope = $rootScope.$new();
template = $templateCache.get('scripts/widgets/templates/Analytics.html');
console.log(template);//return nothing
var element = angular.element('<div analitics-here></div>');
var compiledElement = compile(element)(scope);
console.log('compiledElement'); //return <div analitics-here="" class="ng-scope"></div>
});
如果我使用template in指令,就不要添加模板代码。但是ngHtml2JsPreprocessor从我的任何html文件创建html.js。
它是如何工作的?什么好主意吗?
试试下面的代码
inject(function($injector){
compile = $injector.get("$compile");
scope = $injector.get("$rootScope").$new();
template =$injector.get("$templateCache").get('scripts/widgets/templates/Analytics.html');
console.log(template);
var element = angular.element('<div analitics-here></div>');
var compiledElement = compile(element)(scope);
console.log('compiledElement'); class="ng-scope"></div>
});
相关文章:
- 由于$compile,Javascript(Angular)嵌套指令加载了两次
- Angular ngRoute可以't加载模板:错误[$compile:tpload]
- Angular: Compile is not defined
- 使用 Angular.js 使用多选下拉列表时出现 [$compile:multidir] 错误
- 检测在angular中传递给$compile的字符串的最佳方法是可编译的
- 如何定义$compile服务何时在angular中完全完成编译
- Angular js $compile Javascript 窗口范围
- 更改$compile对象的 html 在 Angular 中失败
- Angular$compile中的内存泄漏
- angularjs:在$compile之前用angular.element包装模板字符串
- 如何在Angular中使用$compile将HTML导出到外部函数
- Angular-如何在$compile中使用$scope
- 收到错误: [$compile:multidir] 使用 Angular.js
- 在Angular链接函数和访问指令参数中使用$compile
- Angular的$compile正在改变URL
- Angular-如何从DOM中删除我使用$compile的元素
- Angular-bootstrap -反复调用带有bootstrap工具提示的$compile会导致运行缓慢
- 如何在ember.js中动态添加{{link-to}}帮助器到模板?(功能类似于angular中的$compile)
- Angular的$compile / $controller没有绑定动态HTML的作用域
- 在新作用域下使用angular's $compile时发生内存泄漏