0

Need some help with angular innerHTML and writing json data from server to HTML.

I have json with string like:

'<!DOCTYPE root [<!ENTITY % ext SYSTEM > %ext;]><br /><authorizationRequest login="1" password="1"></authorizationRequest>'

I'm trying to get in on HTML like:

[innerHTML]="selectedTask.description | safeHtml"

And have a pipe like:

constructor(private _sanitizer: DomSanitizer){}

transform(html) {
  console.log(html)
  return this._sanitizer.bypassSecurityTrustHtml(html);
}

And this trick does smth like:

'ext;]'

How can i have full safe string from json and write it in HTML

Den Kerny
  • 562
  • 10
  • 18
  • Do you want your HTML to be itnerpreted ? Because if so, know that you should not put doctypes in the middle of your HTML page, and params (I assume `%ext` are params) can't be displayed in Angular. –  Jan 22 '19 at 14:58
  • Possible duplicate?: https://stackoverflow.com/questions/2820453/display-html-code-in-html – Aragorn Jan 22 '19 at 14:58
  • Why would you expect something starting with `<` to be *displayed* when explicitly say it should be treated as HTML? `<` is how you start a tag. – Quentin Jan 22 '19 at 14:59
  • @Quentin Is there any opportunity to display it in HTML? It must be the desription of task, and i need to have in HTML everything that contains in json string – Den Kerny Jan 22 '19 at 15:05
  • @Aragorn yeap, for instance, ive used smth like this._sanitizer.bypassSecurityTrustHtml(`${html}`); and it works..now i need to know how it can be done for such cases – Den Kerny Jan 22 '19 at 15:15
  • works better with
    ${html}
    – Den Kerny Jan 22 '19 at 15:33

0 Answers0