我有一个外部JS文件,其中包含一些方法和第三方库的集成。现在,我想将此JS文件作为模块包含在Ionic 2 rc构建项目中。我遵循的步骤如下:
declare module 'Appgeneral'; 在文件中 src/declarations.d.ts
由于它是一个JS文件,因此<script>在中包含标记index.html
在中创建对象home.ts: var appgeneral = new Appgeneral();
Appgeneral.js包含以下代码:
function Appgeneral(){}
Appgeneral.prototype.methodCall = function() {
console.log("Done!");
return true;
};
Run Code Online (Sandbox Code Playgroud)home.ts使用新创建的对象时应该可以访问这些方法appgeneral。在beta.11版本中,它运行良好。但是,升级到rc build之后,我收到一条错误消息,指出无法解析该模块Appgeneral。
另外,我将我转换Appgeneral.js为Appgeneral.ts导出整个类,如下所示:
module Appgeneral{
export class Appgeneral{
public methodCall() {
console.log("Done!");
return true;
}
}
}
Run Code Online (Sandbox Code Playgroud)
于是,我试图将其导入的home.ts如下:import { Appgeneral } from './src/ts/Appgeneral'。但是,错误仍然存在。
找不到名称“ Appgeneral”。L14:构造函数(公共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
Run Code Online (Sandbox Code Playgroud)
这些是我的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"
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
594 次 |
| 最近记录: |