4

I want to use an external javascript library in an angular 4 component but I am having trouble using it. The library I want to install is the plaid link library and I have downloaded the .js file and added it to the assets folder and included it into angular-cli.json scripts location.

The object imported from the class is giving me the error Plaid is not defined. How can I successfully include the pure javascript file into angular typescript?

This is the file I would like to include:

https://cdn.plaid.com/link/v2/stable/link-initialize.js

Thanks

9
  • The class from the file is not showing up in my component. What does that mean? Commented Jul 10, 2017 at 22:05
  • I am gettting the error when I run the constructor: Plaid is not defined. Commented Jul 10, 2017 at 22:12
  • I see. Does the library come with a type definition (*.d.ts) file? I think that is all you are missing. Here is a link to the steps you follow to add a 3rd party library to a ng4 project. The npm install @types... step might be what you are missing. Commented Jul 10, 2017 at 22:15
  • There aren't any types because the library is meant to be run in pure javascript. Commented Jul 10, 2017 at 22:17
  • What about adding a simple script tag in your index.html? Commented Jul 10, 2017 at 22:28

1 Answer 1

3

It looks like your library has a Plaid object, which is not known to the TypeScript compiler.Create a file src/typings.d.ts with the following content:

declare var Plaid: any;

Or you can declare this variable inside your component:

var Plaid: any;
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.