问题描述
我正在使用Angular和ngx-quill。我有一个自定义工具栏按钮,它将插入具有某些属性的文本。我想在单击时选择该文本。
这是我到目前为止所拥有的:
export class InsertDemographic extends Embed {
static blotName: string = "demographic";
static tagName: string = "span";
static className: string = "demographic";
static create(demographic: Demographic) {
let node = super.create();
node.setAttribute('data-demographic_id',demographic.id);
node.innerHTML = `[${demographic.name.replace(" ","_")}]`;
node.addEventListener("click",() => {
console.log(this);
/* const range = this.quill.getSelection(true);
this.quill.setSelection(range.index - 1,1,'user'); */
});
return node;
}
static value(node){
return {
name: node.textContent.replace(/[\[\]]/g,""),id: node.dataset.demographic_id
} as Demographic;
}
}
我添加了一个click事件监听器,该监听器应该获取当前的羽毛笔实例,以获取并设置选择内容。注释过的代码可以工作,但我不知道如何获取主轴实例!
当前,此代码位于与我的编辑器组件分离的文件中,该编辑器组件扩展了工具栏并映射自定义图标等。该单独的文件位于组件外部,这使得管理羽毛笔实例变得困难,不确定是否采用了正确的方法
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)