Angularjs+Typescript 指令实现 $compile [英] Angularjs+Typescript directive implementing $compile
本文介绍了Angularjs+Typescript 指令实现 $compile的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在以下指令中注入 $compile 时遇到问题.
I am having issues injecting $compile in the following directive.
export class Element {
public link(scope:dirScopeInterface, element:any, attrs:ng.IAttributes, formCtrl:ng.IFormController) {
var attr = this.arrayJoiner(scope.standard, scope.attrs || {}, scope.ignore || {});
element.html(this.compiler(attr));
$compile(element.contents())(scope);
}
}
目前它正在抛出一个 $compile is undefined 错误.我试过使用
At the moment it is throwing an $compile is undefined error. I have tried using
static $inject = ['$compile'];
但是由于某种原因它从转译的脚本中消失了.
But it disappears from the transpiled script for some reason.
这里是使用的完整代码.
推荐答案
所以我找到了让它工作的方法,但它没有我想要的那么优雅.
So I found a way to get it to work but it is not as elegant as I would have liked.
angular.module('formDirectives', [], function($compileProvider){
$compileProvider.directive('catElement', ($compile) => {
return new Element($compile);
});
})
这篇关于Angularjs+Typescript 指令实现 $compile的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文