jfcere / ngx-markdown

Angular markdown component/directive/pipe/service to parse static, dynamic or remote content to HTML with syntax highlight and more...
https://jfcere.github.io/ngx-markdown
MIT License
1.05k stars 181 forks source link

Markdown doesn't refresh when input changes, even with change detector #384

Open Atlinx opened 2 years ago

Atlinx commented 2 years ago

I have a bit of html that is supposed to render data fetched from a backend in markdown:

<markdown katex lineNumbers>
  {{ project.description }}
</markdown>

I run a change detector after fetching the data in order to update all the view

this.changeDetector.detectChanges();

However, the markdown component renders nothing, because it's only taking the initial value of project.description, which is empty.

Atlinx commented 2 years ago

I've worked around this by forcing a rebuild using ngIf

<markdown katex lineNumbers *ngIf="isMarkdownReady">
  {{ project.description }}
</markdown>
jfcere commented 2 years ago

Hi @Atlinx,

Thanks for reporting the issue. As a workaround, you can use the data input property which will render the markdown correctly when the value is updated.

<markdown
  katex
  lineNumbers
  [data]="project.description">
</markdown>