This function will do the work:
function decodeSpecialEntitiesHtml(html) {
const str = document.createElement("textarea");
str.innerHTML = html;
return str.value;
}
var html = '<p>mcq-1 A</p>'
document.getElementById('withoutFunction').innerText = html;
document.getElementById('withFunction').innerText = decodeSpecialEntitiesHtml(html);
<label>without func:</label><div id="withoutFunction"></div>
<br>
<label>with func:</label><div id="withFunction"></div>
<br>
So you can use it like:
<div class="card p-3 mb-3" [innerText]="decodeSpecialEntitiesHtml(mcq.question)">
Because you want HTML to behave like text. So basically it is a text that is look like a html. so bind it with innerText
.
TypeScript
The typescript-friendly function will be:
public decodeSpecialEntitiesHtml(html) {
const str = document.createElement("textarea");
str.innerHTML = html;
return str.value;
}
and use it in template like:
<div [innerText]="decodeSpecialEntitiesHtml(serverHtmlResponse)"></div>