title: Angular - Recursive function throws error when calling itself?
body: <p>I have a recursive function that works perfectly fine when outside of angular. It is all native JS but seems to throw errors when trying to use it within angular2/4.</p>
  
  <p><strong>Function:</strong></p>
  
  <pre><code>convertToArray(object, keys) {
      Object.keys(object).forEach(function (k) {
          if (object[k] &amp;&amp; typeof object[k] === 'object') {
              this.convertToArray(object[k], keys);
          }
          if (keys.indexOf(k) !== -1 &amp;&amp; !Array.isArray(object[k])) {
              object[k] = [object[k]];
          }
      });
  }
  </code></pre>
  
  <p>I invoke the method by:</p>
  
  <pre><code>console.log(this._utils.convertToArray(this.mapRulesData, ['rule']))
  </code></pre>
  
  <p>When I run it within my project, I am getting the following error:</p>
  
  <pre><code>TypeError: Cannot read property 'convertToArray' of undefined
  </code></pre>
  
  <p>When I do some <code>console.log</code> within the function, it appears to make it to this line before throwing the error:</p>
  
  <pre><code>this.convertToArray(object[k], keys);
  </code></pre>
  
  <p>Is there something special with angular when trying to have a method call itself in this manner?</p>