I have a scenario where I need to display html and xml from the same string sent from the server.
The reply from the server looks like this:
This is sample text with <b>bold text</b> and also some xml like this <note><to>you</to><from>me</from><heading>title</heading><body>message</body></note>. As you can see it contains both xml to display and html to render.
I tried:
text;
msg = 'This is sample text with <b>bold text</b> and also some xml like this <note><to>you</to><from>me</from><heading>title</heading><body>message</body></note>. As you can see it contains both xml to display and html to render.'
constructor(private domSanitizer: DomSanitizer) {
}
ngOnInit() {
this.text = this.getInnerHTMLValue();
}
getInnerHTMLValue() {
return this.domSanitizer.bypassSecurityTrustHtml(this.msg);
}
html:
<pre [innerText]="text"></pre>
I get this error:
SafeValue must use [property]=binding:...
And when I use [innerHTML]
instead of [innerText]
the xml has been cleaned out.
How can I display sample xml code along with parsing html tags such as <b>
tags?
At the very least how can I get rid of that error?