编译时的es6指令返回[object HTMLElement]

时间:2018-12-06 06:30:39

标签: angularjs ecmascript-6 es6-class

我需要附加一个元素指令"<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])

0 个答案:

没有答案