title: Using external js file in angular 6 component
body: <p>I am trying to use a js file into my angular 6 application. Steps I followed are as follows: </p>
  
  <p><strong>1. Created <code>testfile.js</code> file:</strong></p>
  
  <blockquote>
  <pre><code>var testa = function () {
     function testMethod() {
          console.log('hello');
      }
  }
  var testmodule = new testa();
  module.exports = testmodule;
  </code></pre>
  </blockquote>
  
  <p><strong>2. In <code>angular.cli.json</code>. For testing purpose tesfile.js is at the same location as <code>angular.cli.json</code> is:</strong> </p>
  
  <blockquote>
  <pre><code> "scripts": [
                "testfile.js"
              ],
  </code></pre>
  </blockquote>
  
  <p><strong>3. In typings.d.ts file, declared it:</strong></p>
  
  <blockquote>
    <p><code>declare var testmodule: any;</code></p>
  </blockquote>
  
  <p><strong>4. In ts file, tried to use it as:</strong></p>
  
  <blockquote>
  <pre><code> public ngOnInit() {
          testmodule.testMethod()
      }
  </code></pre>
  </blockquote>
  
  <p>But when angular component is used, warning in console is: </p>
  
  <pre><code>Uncaught ReferenceError: testmodule is not defined
  </code></pre>
  
  <p>I tried another alternative, like importing js file inside .ts file as: </p>
  
  <ol>
  <li><code>import * as mymodule '../../testfile.js'</code></li>
  <li><code>"allowJs":  true</code>
  but this is also not identifying testmodule or testfile. </li>
  </ol>
  
  <p>What wrong am I doing here? </p>