问题
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.
angular.json
add below"styles": [ "node_modules/trix/dist/trix.css" ], "scripts": [ "node_modules/trix/dist/trix.js" ]
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>
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