0

I have a requirement that my API will return XML response. I want to display it on HTML page using Angular2. How do I achieve that? I am using xml2js node module to parse xml. this is my code

 import * as xml2js from 'xml2js';
  /* This is sample demo I am working on.In future data will come 
      from API
  */
  showData() {
     const xml = '<root>Hello xml2js!</root>';
      xml2js.parseString(xml, function (err, result) {
      console.dir(result);
    });
  }

From the above code I want to display "Hello xml2js" in HTML page. How do I achieve that in angular 2?

In console I get following result: enter image description here Thanks in Advance.

hemantmali
  • 63
  • 2
  • 13

1 Answers1

0
  import * as xml2js from 'xml2js';

  text = "";
/* This is sample demo I am working on.In future data will come 
      from API
  */
  showData() {
     const xml = '<root>Hello xml2js!</root>';
      xml2js.parseString(xml, function (err, result) {
      this.text = result;
    });
  }

In html

<p>{{text}}</p>
Praneeth Reddy
  • 424
  • 3
  • 7