title: Angular / Typescript Cannot set property 'data' of undefined
body: <p>I have some code which is reading xml then parsing the data.</p>
  
  <p>So here's the code:</p>
  
  <pre><code>data = [];
  
    ngOnInit() {
    this.myService.getData().subscribe(XMLResult =&gt; {
      const parseString = require('xml2js').parseString;
      parseString(XMLResult, function (err, result) {
         console.dir(result.listResponse.instance); // Returns Array
         this.data = result.listResponse.instance; // Here's the line giving me the error
      });
  
   });
  }
  </code></pre>
  
  <p>Console.log is returning the data like this:</p>
  
  <pre><code>Array(10)
    0:
     $: {id: "23" name: "name 1"}
    1:
     $: {id: "45" name: "name 2"}
  </code></pre>
  
  <p>etc</p>
  
  <p>How can I fix this problem?</p>