0

I am creating an app which uses angular 6 in frontend and laravel 5.8 as backend. One api returns response as html code that should be saved in html format file and open in browser. How can I do this in angular 6.

I tried below code, but not working

<div class='html-redirect' innerHTML="{{data}}"></div>

I am new to angular.

Any help would be appreciated, thanks.

Nagesh Katke
  • 540
  • 7
  • 23
  • Possible duplicate of [Angular HTML binding](https://stackoverflow.com/questions/31548311/angular-html-binding) – magnattic Sep 13 '19 at 10:28

2 Answers2

0

Try this code:

<div class="html-redirect" [innerHTML]="data"></div>
qwerty
  • 679
  • 5
  • 12
0

You need to run the HTML string through DomSanitizer.bypassSecurityTrustHtml() before outputting it in the template. Otherwise Angular will encode the untrusted HTML.

magnattic
  • 12,638
  • 13
  • 62
  • 115
  • I am trying this, but my response contains javascript functions which suppose to redirect bank payment url, which is not happening. I tried @qwerty's solution also, but no help. – Nagesh Katke Sep 13 '19 at 10:29
  • Please add more context to the question then. :) You could try running it through `bypassSecurityTrustScript()` as well, but I'm not sure what you are trying to achieve even makes sense. Why are you loading scripts that way? – magnattic Sep 13 '19 at 10:32
  • I hit a third party api which returns me html code in xml, I need to open that html code in browser which has javascript functions of redirections. basically that html page is payment page of bank. I don't know how to do that. :( – Nagesh Katke Sep 13 '19 at 10:35
  • We won't be able to help you without knowing more about the API. But why don't you open it in a separate tab (just add a link to the API page)? – magnattic Sep 13 '19 at 10:36
  • 1
    I solve this by using `document.write(res.data);` which redirects me to desired third party web page. Thanks for your time and help. :) – Nagesh Katke Sep 13 '19 at 13:42