错误试图执行鹅毛笔,更好,表与角鹅毛笔编辑器组件时

如何解决错误试图执行鹅毛笔,更好,表与角鹅毛笔编辑器组件时

我尝试使套筒,更好,表工作没有成功的几种方法,大多数的例子在那里是不是角,我收到指出“不能读取属性未定义‘insertTable’”的错误我将在下面包含我的代码和错误,请帮助我。注意:这是指在生产中使用的应用

这是我的 HTML 代码:

<div class="card">
  <div ibmGrid>
    <div ibmRow>
      <div ibmCol>
        <button ibmButton="secondary" size="sm" (click)="onInsertTable()">Add table</button>

        <form [formGroup]="editorForm" (ngSubmit)="onSubmit()">
          <div class="form-group">
            <quill-editor [styles]="editorStyle" [modules]="config" formControlName="editor" (onEditorCreated)="editorCreated($event)"></quill-editor>
          </div>
         
          <button ibmButton="primary">Save changes</button>
        </form>
      </div>
    </div>
</div>

这是我的 Angular TS 代码:

 import { Component,OnInit,AfterViewInit,ChangeDetectionStrategy } from '@angular/core';
import { FormControl,FormGroup } from '@angular/forms';
import { DropdownModule,ModalService } from 'carbon-components-angular';
import * as quillBetterTable from 'quill-better-table';


interface Quill {
  getModule(moduleName: string);
}

interface BetterTableModule {
  insertTable(rows: number,columns: number): void;
}

// declare const require: any;
// let Quill: any = null;


@Component({
  selector: 'app-fnl-report',templateUrl: './fnl-report.component.html',styleUrls: ['./fnl-report.component.scss'],// changeDetection: ChangeDetectionStrategy.OnPush
})
export class FnlReportComponent implements OnInit {

  editorForm: FormGroup
  public quill: Quill;

  editorStyle = {
    height: '500px',backgroundColor: '#fff'
  }

  config = {
    toolbar: [
      ['bold','italic','underline','strike'],// toggled buttons
      ['blockquote','code-block'],[{ 'header': 1 },{ 'header': 2 }],// custom button values
      [{ 'list': 'ordered'},{ 'list': 'bullet' }],[{ 'script': 'sub'},{ 'script': 'super' }],// superscript/subscript
      [{ 'indent': '-1'},{ 'indent': '+1' }],// outdent/indent
      // [{ 'direction': 'rtl' }],// text direction
      [{ 'size': ['small',false,'large','huge'] }],// custom dropdown
      [{ 'header': [1,2,3,4,5,6,false] }],[{ 'color': [] },{ 'background': [] }],// dropdown with defaults from theme
      [{ 'font': [] }],[{ 'align': [] }],['clean'],// remove formatting button
      ['link']                                          // link and image,video ['link','image','video']  
    ]
  }

  constructor() { }

  ngOnInit() {
    this.editorForm = new FormGroup({
      'editor': new FormControl(null)
    });  
  }

  public editorCreated(event: Quill): void {
    this.quill = event;
    // Example on how to add new table to editor
    this.addNewtable();
  }

  private get tableModule(): BetterTableModule {
    return this.quill.getModule("better-table");
  }

  private addNewtable(): void {
    this.tableModule.insertTable(3,3);
    console.log('Hi');
  }

  onSubmit() {
    console.log(this.editorForm.get('editor').value);
  }

  onInsertTable() {
    // const tableModule = this.quill.getModule('better-table');
    // tableModule.insertTable(3,3);
  }

}

这是我的模块文件:

import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { LoadingModule,DropdownModule,GridModule,FileUploaderModule,DialogModule,ButtonModule } from 'carbon-components-angular';
import { Help16Module } from '@carbon/icons-angular/lib/help/16';
import { UploadFilesComponent } from './upload-files/upload-files.component';
import { FnlReportComponent } from './fnl-report/fnl-report.component';
import { ReactiveFormsModule } from '@angular/forms';
import { QuillModule,QuillConfig } from "ngx-quill";
import * as Quill from "quill";
import QuillBetterTable from "quill-better-table";


Quill.register(
  {
    "modules/better-table": QuillBetterTable
  },true
);

const quillConfig: QuillConfig = {
  modules: {
    table: false,// disable table module
    "better-table": {
      operationMenu: {
        items: {
          unmergeCells: {
            text: "Another unmerge cells name"
          }
        },color: {
          colors: ["#fff","red","rgb(0,0)"],// colors in operationMenu
          text: "Background Colors" // subtitle
        }
      }
    },keyboard: {
      bindings: QuillBetterTable.keyboardBindings
    }
  }
};


@NgModule({
  declarations: [
    UploadFilesComponent,FnlReportComponent
  ],imports: [
    CommonModule,LoadingModule,ButtonModule,Help16Module,ReactiveFormsModule,QuillModule.forRoot(quillConfig)
  ],providers:[],exports: []
})
export class ImsHubModule { }

这是我的CSS进口翮:

@import '~quill/dist/quill.core.css';
@import '~quill/dist/quill.bubble.css';
@import '~quill/dist/quill.snow.css';

这是我的套筒的package.json依赖性和套筒轴表:

"dependencies": {
    "ngx-quill": "^13.0.1","quill": "^1.3.7","quill-better-table": "^1.2.10"
}

这是我得到的错误:

FnlReportComponent.html:24 ERROR TypeError: Cannot read property 'insertTable' of undefined

解决方法

不幸的是,您不能将 quill-better-table 与 ngx-quill 包装器一起使用。 ngx-quill 仍然基于 quilljs v1。 quill-better-table 需要 quilljs v2.0.0-dev.3。 您可以在“要求”部分阅读相关内容:here

在我的案例中,我可以与您分享我是如何实现简单的粘贴和读取表格的。它的灵感来自 this article 并使用自定义块创建。并且它不是向羽毛笔添加元素的正确方法。但我们在内部使用编辑器,所以我们确信它是安全的。

  1. 像这样创建一个新的“块嵌入”:
import Quill from 'quill';
const BlockEmbed = Quill.import('blots/block/embed');

    export class TableBlockEmbed extends BlockEmbed {

      static blotName = 'TableBlockEmbed';
      static tagName = 'table';

      static create(value) {
        const node = super.create();
        let valueToReturn = value;
        if (!value.includes('assignedTableId')) {
          const tableId = `assignedTableId-${Date.now()}`;
          valueToReturn = value
            .replace('#tableId',`#${tableId}`)
            .replace('table-layout: fixed;','');
          node.setAttribute('id',tableId);
        } else {
          const existedId = valueToReturn.match(/#assignedTableId-(\d+)/i)[1];
          node.setAttribute('id',`assignedTableId-${existedId}`);
        }
        node.innerHTML = this.transformValue(valueToReturn);
        return node;
      }

      static transformValue(value) {
        let handleArr = value.split('\n');
        handleArr = handleArr.map(e => e.replace(/^[\s]+/,'')
          .replace(/[\s]+$/,''));
        return handleArr.join('');
      }

      static value(node) {
        return node.innerHTML;
      }
    }
  1. 在使用 ngx-quill 的组件的构造函数中运行新嵌入块的注册:
constructor() {
    Quill.register(TableBlockEmbed,true);
  }
  1. 添加编辑器在下面创建了此代码。 (您当然可以在此处添加/删除您需要的样式。例如,我添加了 margin: 0 auto !important; 因为我想强制表格始终居中):
onEditorCreated(quill: Quill): void {
    quill.clipboard.addMatcher('TABLE',(node,delta) => {
      const Delta = Quill.import('delta');
      const tableTagStyles = node.getAttribute('style');
      return new Delta([
        {
          insert: {
            TableBlockEmbed:
              `<style>#tableId {${tableTagStyles} margin: 0 auto !important; }</style>` + delta.ops[0].insert.TableBlockEmbed
          }
        }
      ]);
    });
  }
  1. 我还添加了一些样式:
quill-view,quill-editor{
  ::ng-deep {
    table {
      width: 100%; // if table has no width - then give it by default 100%
      max-width: 100% !important;
      box-sizing: border-box;
    }
  }
}

我知道这个解决方案只是一种解决方法,但在等待基于 quill 2 的 ngx-quill 之前,我至少能够提供在编辑器中粘贴表格的功能,这看起来很不错。

示例:

office word 中的表格:

enter image description here

ngx-quill 中的表格:

enter image description here

excel表格:

enter image description here

ngx-quill 中的表格:

enter image description here

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


依赖报错 idea导入项目后依赖报错,解决方案:https://blog.csdn.net/weixin_42420249/article/details/81191861 依赖版本报错:更换其他版本 无法下载依赖可参考:https://blog.csdn.net/weixin_42628809/a
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下 2021-12-03 13:33:33.927 ERROR 7228 [ main] o.s.b.d.LoggingFailureAnalysisReporter : *************************** APPL
错误1:gradle项目控制台输出为乱码 # 解决方案:https://blog.csdn.net/weixin_43501566/article/details/112482302 # 在gradle-wrapper.properties 添加以下内容 org.gradle.jvmargs=-Df
错误还原:在查询的过程中,传入的workType为0时,该条件不起作用 &lt;select id=&quot;xxx&quot;&gt; SELECT di.id, di.name, di.work_type, di.updated... &lt;where&gt; &lt;if test=&qu
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct redisServer’没有名为‘server_cpulist’的成员 redisSetCpuAffinity(server.server_cpulist); ^ server.c: 在函数‘hasActiveC
解决方案1 1、改项目中.idea/workspace.xml配置文件,增加dynamic.classpath参数 2、搜索PropertiesComponent,添加如下 &lt;property name=&quot;dynamic.classpath&quot; value=&quot;tru
删除根组件app.vue中的默认代码后报错:Module Error (from ./node_modules/eslint-loader/index.js): 解决方案:关闭ESlint代码检测,在项目根目录创建vue.config.js,在文件中添加 module.exports = { lin
查看spark默认的python版本 [root@master day27]# pyspark /home/software/spark-2.3.4-bin-hadoop2.7/conf/spark-env.sh: line 2: /usr/local/hadoop/bin/hadoop: No s
使用本地python环境可以成功执行 import pandas as pd import matplotlib.pyplot as plt # 设置字体 plt.rcParams[&#39;font.sans-serif&#39;] = [&#39;SimHei&#39;] # 能正确显示负号 p
错误1:Request method ‘DELETE‘ not supported 错误还原:controller层有一个接口,访问该接口时报错:Request method ‘DELETE‘ not supported 错误原因:没有接收到前端传入的参数,修改为如下 参考 错误2:cannot r
错误1:启动docker镜像时报错:Error response from daemon: driver failed programming external connectivity on endpoint quirky_allen 解决方法:重启docker -&gt; systemctl r
错误1:private field ‘xxx‘ is never assigned 按Altʾnter快捷键,选择第2项 参考:https://blog.csdn.net/shi_hong_fei_hei/article/details/88814070 错误2:启动时报错,不能找到主启动类 #
报错如下,通过源不能下载,最后警告pip需升级版本 Requirement already satisfied: pip in c:\users\ychen\appdata\local\programs\python\python310\lib\site-packages (22.0.4) Coll
错误1:maven打包报错 错误还原:使用maven打包项目时报错如下 [ERROR] Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:resources (default-resources)
错误1:服务调用时报错 服务消费者模块assess通过openFeign调用服务提供者模块hires 如下为服务提供者模块hires的控制层接口 @RestController @RequestMapping(&quot;/hires&quot;) public class FeignControl
错误1:运行项目后报如下错误 解决方案 报错2:Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project sb 解决方案:在pom.
参考 错误原因 过滤器或拦截器在生效时,redisTemplate还没有注入 解决方案:在注入容器时就生效 @Component //项目运行时就注入Spring容器 public class RedisBean { @Resource private RedisTemplate&lt;String
使用vite构建项目报错 C:\Users\ychen\work&gt;npm init @vitejs/app @vitejs/create-app is deprecated, use npm init vite instead C:\Users\ychen\AppData\Local\npm-