ngx-markdown icon indicating copy to clipboard operation
ngx-markdown copied to clipboard

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

Open Atlinx opened this issue 2 years ago • 2 comments

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 avatar Jun 04 '22 15:06 Atlinx

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

<markdown katex lineNumbers *ngIf="isMarkdownReady">
  {{ project.description }}
</markdown>

Atlinx avatar Jun 04 '22 15:06 Atlinx

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>

jfcere avatar Jun 04 '22 18:06 jfcere