angularmarkdown-it

How to add Markdown-it to angular 8


I wonder if anyone knows how to add Markdown-it to an existing Angular 8 application. I have installed the package with npm install but don't know how to import it into my component. Does anyone know how to do this? Thanks in advance!


Solution

  • install markdown-it

    npm i markdown-it
    

    import { Component, OnInit } from '@angular/core';
    import md from 'markdown-it';
    @Component({
      selector: 'app-root',
      templateUrl: './app.component.html',
      styleUrls: ['./app.component.css']
    })
    export class AppComponent implements OnInit {
      private markdown;
      outHtml;
      constructor(){
        this.markdown=md();
        this.outHtml=this.markdown.render("# Ahmad Hamzavi");
      }
    
      ngOnInit() {
      }
    
    }
    <span [innerHTML]="outHtml" ></span>