我需要附加一个元素指令"<my-directive></my-directive>"
,但是
尝试在另一个控制器中编译指令时,它仅返回一个对象,而不是html。
考虑以下内容作为示例指令
export default class myDirective{
constructor($document, $window, $rootScope,$timeout,$compile) {
this.restrict = 'E';
this.scope = {
requrl: '@'
};
this.templateUrl = 'path.html';
this.controller = myController;
this.controllerAs = '$ctrl';
this.bindToController = true;
this.transclude = true;
}
link(scope, element, attrs) {}
static myDirectiveFactory($document, $window, $rootScope, reqs, $timeout, $compile) {
myDirective.instance = new myDirective($document, $window, $rootScope, reqs, $timeout, $compile);
return myDirective.instance;
}
}
在下面添加了编译代码
this.$compile('<my-directive></my-directive>')(this.$scope)[0])