I am trying to include an external library in ionic Winwheel.min.js
to be more exact
I followed the steps suggested by a document I found on the internet
1.Copy the library to the addresswww/assets/js/
2.Import the library in src/index.html
<script src="assets/js/winwheel.min.js" async defer></script>
3.Go to home.ts declare a global variable with the name of the Library
declare var Winwheel:any;
I have my doubts about the step 3
then use the library
let theWheel = new Winwheel({});
It shows me the following error.
ERROR Error: Uncaught (in promise): ReferenceError: Winwheel is not defined ReferenceError: Winwheel is not defined at HomePage.webpackJsonp.196.HomePage.CrearRuleta (home.ts:19) at new HomePage (home.ts:14) at createClass (core.js:12481) at createDirectiveInstance (core.js:12326) at createViewNodes (core.js:13784) at createRootView (core.js:13673) at callWithDebugContext (core.js:15098) at Object.debugCreateRootView [as createRootView ] (core.js:14381) at ComponentFactory_.create (core.js:11278) at ComponentFactoryBoundToModule.create (core.js:4030) at HomePage.webpackJsonp.196.HomePage.CrearRuleta (home.ts:19) at new HomePage (home.ts:14) at createClass (core.js:12481) at createDirectiveInstance (core.js:12326) at createViewNodes (core.js:13784) at createRootView (core.js:13673) at callWithDebugContext (core.js:15098) at Object.debugCreateRootView [as createRootView] (core.js:14381) at ComponentFactory_.create (core.js:11278) at ComponentFactoryBoundToModule.create (core.js:4030) at c (polyfills.js:3) at c (polyfills.js:3) at polyfills.js:3 at t.invokeTask (polyfills.js:3) at Object.onInvokeTask (core.js :4751) at t.invokeTask (polyfills.js:3) at r.runTask (polyfills.js:3) at o (polyfills.js:3)3) at polyfills.js:3 at t.invokeTask (polyfills.js:3) at Object.onInvokeTask (core.js:4751) at t.invokeTask (polyfills.js:3) at r.runTask (polyfills.js: 3) at or (polyfills.js:3)3) at polyfills.js:3 at t.invokeTask (polyfills.js:3) at Object.onInvokeTask (core.js:4751) at t.invokeTask (polyfills.js:3) at r.runTask (polyfills.js: 3) at or (polyfills.js:3)
Following the steps that IONIC recommends for third-party libraries:
You must do the following:
First:
Then you must import it in each file that you want to use it:
Generic example of installation, import and use:
In the project directory, by console:
Then in the files you want to make use of the Lib:
Recommendation and best practices:
It is more advisable to import only the function you want to use in that particular file, it may not always be possible depending on the library, it is done in the following way:
With IONIC you can basically install libraries in two ways, and depending on what you want to install the command varies, the ways it works are the following:
Applying these concepts to your question, we know that you want to install a JavaScript library , so we will visit the official NPM page and look for the library you need , according to the documentation that it shows in the NPM installation it tells us to do the following: