How do I integrate trix-editor in an angular 2 app?

大憨熊 提交于 2020-01-24 04:28:08

问题


I am trying to use trix editor for my angular app. However, I am not getting any resources/npm packages to install trix editor in an angular 2 app. Can you help me with the resources/steps to do so?


回答1:


I also can not find any for angular2+. Just set it up.

  1. angular.json
    add below

    "styles": [
        "node_modules/trix/dist/trix.css"
     ],
    "scripts": [
        "node_modules/trix/dist/trix.js"
     ]
    
  2. attach editor at HTML you want to put it.
    angular using as selector and trix using as target location of editor.
    It conflict. so need some trick.

    <form>
      <input id="x" type="hidden" name="content">
      <trix-editor #trixEditor class="trix-content" input="x"
                [editor]="trixEditor"></trix-editor>
    </form>
    
  3. make trixComponent for child html
    for trick, need to make component. receivce 'editor' element from mother html.

    @Component({
    // tslint:disable-next-line:component-selector
    selector: 'trix-editor',
    templateUrl: './trix.component.html'
    })
    export class TrixComponent implements OnInit {
    
    @Input() editor: any;
    
    constructor() {
    }
    
    ngOnInit() {
      const element: any = document.querySelector('trix-editor');
      console.log(element.editor.getDocument());
      element.addEventListener('trix-attachment-add', (event) => {
        if (event.attachment.file) {
           console.log(event);
        }
      });
    }
    
    }
    



回答2:


If you are using devextreme, I think you can consider to use devextreme html editor https://github.com/DevExpress/DevExtreme/releases https://js.devexpress.com/Documentation/18_2/ApiReference/UI_Widgets/dxHtmlEditor/



来源:https://stackoverflow.com/questions/49852353/how-do-i-integrate-trix-editor-in-an-angular-2-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!