I am trying to display code in html and prettify it using Google Code prettify. I am almost close to completion of my requirement, but when I try to externalize the file and pull code from it, it isn't working.
Here is my ts code snippet.
demoJavaCode: any;
demoJavaCodeFromFile: any;
ngOnInit() {
this.demoJavaCode =
`<pre><xmp class="prettyprint">
public class A {
public static void main(String args[]) {
}
}
</xmp></pre>`;
}
ngAfterViewInit() {
PR.prettyPrint();
}`
In template, I am fetching it like this.
<p [innerHtml] ="demoJavaCode | trustedHtml"></p>
It works well, the paragraph which has code in it is highlighted/prettified only when it is sanitized using trustedHTML pipe.
But when I just tried to externalize the code to an external file having the exact same code content it's not working.
Here is my ts snippet.
this._http.get("assets/java_code.txt").map(res => res.text()).subscribe(
response => {
this.demoJavaCodeFromFile = response;
},
error => {
this.componentErrorMessage = error;
},
() => {
console.log('File successfully loaded..');
}
);
What could be wrong here? Any pointers and suggestions would help.