Third party libs in Ionic 2


#1

I have an external JS file containing some methods and third party library integration. Now, I want to include this JS file as a module in my Ionic 2 rc build project. The steps that I followed are as follows:

  • declare module 'Appgeneral'; in the file src/declarations.d.ts

  • Including a <script> tag in the index.html since it is a JS file

  • Creating an object in home.ts : var appgeneral = new Appgeneral();

  • Appgeneral.js contains the following code:

      function Appgeneral(){}
      Appgeneral.prototype.methodCall = function() {
              console.log("Done!");
              return true;
      };
    

The methods should be accessible in home.ts using the newly created object appgeneral. It was working fine in the beta.11 version. However, after upgrading to the rc build, I’m getting an error stating cannot resolve the module Appgeneral.

Also, I converted my Appgeneral.js to Appgeneral.ts exporting the entire class.
Then, I tried to import it in the home.ts as follows: import { Appgeneral } from './src/ts/Appgeneral'. Still, the error persists.

Cannot find name ‘Appgeneral’.
L14: constructor(public navCtrl: NavController,
L15: public appgeneral: Appgeneral) {

The documentation provided at Third Party libs is applicable to external libraries which are available on npm. However, I want to include my third party library directly within the app.

This is my ionic info:

Cordova CLI: 6.3.1
Ionic CLI Version: 2.1.0
Ionic App Lib Version: 2.1.0-beta.1
ios-deploy version: 1.8.3
ios-sim version: 5.0.4
OS: Mac OS X El Capitan
Node Version: v6.8.0
Xcode version: Xcode 8.0 Build version 8A218a

These are my package.json dependencies:

“dependencies”: {
"@angular/common": “^2.0.0”,
"@angular/compiler": “^2.0.0”,
"@angular/compiler-cli": “0.6.2”,
"@angular/core": “^2.0.0”,
"@angular/forms": “^2.0.0”,
"@angular/http": “^2.0.0”,
"@angular/platform-browser": “^2.0.0”,
"@angular/platform-browser-dynamic": “^2.0.0”,
"@angular/platform-server": “^2.0.0”,
"@ionic/storage": “^1.0.3”,
“ionic-angular”: “^2.0.0-rc.1”,
“ionic-native”: “^2.2.3”,
“ionicons”: “^3.0.0”,
“rxjs”: “5.0.0-beta.12”,
“zone.js”: “^0.6.21”
}