I have an external JS file containing some methods and integration of third-party libraries. Now I want to include this JS file as a module in my Ionic 2 rc build project. The following steps were as follows:
declare module 'Appgeneral'; in file src/declarations.d.ts
Including tag <script>in index.htmlsince this 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;
};
Methods must be available in home.tsusing the newly created object appgeneral. It worked great in beta.11. However, after upgrading to the rc build, I get an error message that the module cannot resolve appgeneral.
In addition, I converted mine Appgeneral.jsto Appgeneral.tsexport the entire class as follows:
module Appgeneral{
export class Appgeneral{
public methodCall() {
console.log("Done!");
return true;
}
}
}
home.ts : import { Appgeneral } from './src/ts/Appgeneral'. , .
"Appgeneral". L14: (public navCtrl: NavController, L15: public appgeneral: Appgeneral) {
, , , npm. .
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
package.json:
"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"
}