I have an Angular4 project that retrieves an string of HTML content from an API, the HTML can contain multiple blocks of <code>, and I want to highlight these blocks using PrismJS.
To make this work, I need to call Prism.highlightAll() after the content has been rendered in the DOM, when I call Prism.highlightAll() after the API call, this doesn't do anything because the element is not instantaneously rendered, to get it to work I am doing a small wait before calling the renderer, this is not a good solution though, and wanted to know if there is a cleaner solution.
This is what my code currently looks like:
this.dataService.getPageContent().subscribe(
res => {
this.html = this.sanitizer.bypassSecurityTrustHtml(res);
setTimeout(function() { Prism.highlightAll(); }, 2000);
},
err => {
alert('error');
}
);