Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

206
Views
How to import an uploaded JS file?

I have an Angular application using a Plugin- Architecture from this article In this article the build bundle.js file is exported and imported in the application from assets folder using .import(filepath). What I am trying to do is instead of importing the saved file, I want to upload a file and import that file.

I know how to read and evaluate a JS file by uploading using the below code. But, I am not sure how to make it work with an Angular build file. Any idea?

function handleFileInput(files) {
  var fileContent = document.getElementById('contnt');
  var fileToUpload = files.item(0);
  var textType = /text.*/;

  if (fileToUpload.type.match(textType)) {
    var reader = new FileReader();

    reader.onload = function(e) {
      const x = eval(reader.result)
      fileContent.innerText = x;
    }

    reader.readAsText(fileToUpload);
  } else {
    fileContent.innerText = "File not supported!"
  }
}
<input id="fileInput" type="file" name="file" (change)="handleFileInput($event.target.files)" />
<pre id="fileContent"></pre>

<div id="contnt"></div>

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!