我正在做一些项目,并且已经为某些实体创建和编辑页面。两者的html页面是相同的,但是控制器是不同的,我想创建一个包含html的指令,然后将相关的控制器(创建或编辑)“注入”该指令。
我将指令用作ES6中的类,我已经厌倦了使用bindToContoller和controller字段来“注入”我的控制器而没有成功。
import EntityCreateController from '../../create/controller';
class FormDirective
{
constructor() {
this.template = require('./directive.html');
this.restrict = 'E';
this.replace = true;
this.controllerAs = 'ctrl';
this.bindToController = true;
this.controller = EntityCreateController;
this.transclue = true;
this.scope = {
record: '=',
ngModel: '=',
};
this.link = (scope, elem, attrs, controller) => {
controller.EntityCreate = scope.form
};
}
}
export default EntityCreateController;
我在链接功能中将表格附加到控制器时遇到问题。还有其他一些事情没有我期望的那样。