0

In my assets folder, I have a script called 'imageTools.js'. In one of my angular type script files I want to call 'imageTools' but it's unrecognised. What's the best way to do this?

As expected here's the error:

[ts] Cannot find name 'ImageTools'.

Here's my code.

detectFiles(event) {
 this.selectedFiles = event.target.files;
  ImageTools.resize(this.selectedFiles[0], {
    width: 1000, 
    height: 1000 
  }, function (blob, didItResize) {
    this.testingBaseSixtyFour(blob);
  });    
}
  • 3
    Possible duplicate of [using external JS libraries in my angular 2 project](https://stackoverflow.com/questions/41120754/using-external-js-libraries-in-my-angular-2-project) – Ayman El Temsahi Feb 28 '18 at 11:55
  • You're right. Please close. Thanks @AymanElTemsahi –  Feb 28 '18 at 12:04

1 Answers1

0

import your jquery and javascript file in index.html. In your javascript file expose a variable through which you can call your functions.

Initialize that variable in your component and use it in your component it will work for you.

 var detect =  function(){
    detectFiles =function detectFiles(event) {
     this.selectedFiles = event.target.files;
      ImageTools.resize(this.selectedFiles[0], {
        width: 1000, 
        height: 1000 
      }, function (blob, didItResize) {
        this.testingBaseSixtyFour(blob);
      });    
    }
     return detectFiles :detectFiles 
    }

Initiallize detect this variable in your component with return type is any

// detect. detectFiles (event)

like this

Hasnain Bukhari
  • 458
  • 2
  • 6
  • 23