angluar 使用markdown编辑器vditor

  1. npm 安装
    1. npm install vditor --save --force
  2. angular.json引入样式文件node_modules/vditor/src/assets/less/index.less
    1. "styles": [
    2. "node_modules/vditor/src/assets/less/index.less",
    3. ]
  3. component.ts中导入vditor

    1. import { Component, OnInit } from '@angular/core';
    2. import {ActivatedRoute} from '@angular/router';
    3. import Vditor from 'vditor';
    4. @Component({
    5. selector: 'app-article-detail',
    6. templateUrl: './article-detail.component.html',
    7. styleUrls: ['./article-detail.component.less'],
    8. })
    9. export class ArticleDetailComponent implements OnInit {
    10. vditor: Vditor;
    11. constructor(private activatedRoute: ActivatedRoute) { }
    12. ngOnInit() {
    13. this.vditor = new Vditor('vditor', {
    14. height: 360,
    15. //"dark" | "light"
    16. mode: "wysiwyg",
    17. theme: "dark",
    18. toolbarConfig: {
    19. pin: true,
    20. },
    21. cache: {
    22. enable: false,
    23. },
    24. after: () => {
    25. this.vditor.setValue('Hello, Vditor + Angular!');
    26. }
    27. });
    28. }
    29. }
  4. html中
    1. <div id="vditor"></div>
  5. 完成