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

2

6

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?

Udelle answered 16/4, 2018 at 8:4 Comment(0)
C
4

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);
        }
      });
    }
    
    }
    
Consentient answered 24/10, 2019 at 5:41 Comment(0)
A
-3

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/

Alkalosis answered 2/11, 2018 at 4:27 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.