我创建基于ES6风格指令:呼叫链接功能指令角1 ES6
export default class myDirective {
constructor() {
this.restrict = 'E';
this.scope = {};
this.link = link;
}
link() {
console.log('link myDirective');
}
}
然后在index.js
:
import angular from 'angular';
import myDirective from './myDirective';
export default angular
.module('app.directives', [])
.directive('myDirective ',() => new myDirective())
.name;
但是,当我打电话myDirective对HTML这样的:<my-directive><my-directive>
它不调用链接函数或编译函数。我能做什么?
你能尝试删除this.link =链接;来自构造函数。 –
我试过但不起作用:/ –
恩,它对我来说工作正常。唯一的问题是,你的指令有一个空格字符的名称,打破了声明(“myDirective”,删除空间),尽管如此,它为我工作。 –