Nov
Nov

Reputation: 99

Problem using js file in typescript project. Angular CLI

I found a great github project and I was hoping to use it in my project. I'm sure I'm going to run into this problem again. So I'm really hoping I can get help on this. The project is located in the URL: https://github.com/lokesh/color-thief. I am trying to import the js file color-thief.js into my project and use it in a TS file or component. I added the file to my scripts[] in the angular.json file. Yet I'm still running into problems accessing the method getColor(). I am using intelliJ. I can't get the intellisense or code-completion to work. Which is furthermore making me think I'm not importing the file correctly.

Here is my ts file.

declare var ColorThief: any;

The path to get to the js file is

'../../js/color-thief.js'

Environmental setup is a nightmare.

Upvotes: 1

Views: 429

Answers (1)

Yoarthur
Yoarthur

Reputation: 917

Make sure that in your angular.json file, the script property set something like this.

"scripts": [
  "node_modules/[packageName]/js/color-thief.js",
],

remember to set node_modules and in the script, and import the proper .js file when that global variable is defined.

As far as i can see you need to create that object, according to color-thief package. Like this.

 let colorThief = new ColorThief();

Upvotes: 1

Related Questions