我正在尝试通过此链接http://openexchangerates.github.io/money.js/
以不同的格式转换货币我将http://openexchangerates.github.io/money.js/money.js文件复制到了资产/ js /文件中,文件名为“ converter.js”
我也在我的index.html文件中声明了该文件:
<script src="assets/js/converter.js"></script>
现在我想调用fx.convert(1, {from: "USD", to: "INR"});
函数到我的home.ts文件中
我喜欢
declare var fx;
alert(fx.convert(1, {from: "USD", to: "INR"}));
返回错误:
ERROR Error: fx error
at viewWrappedDebugError (VM263 vendor.js:10180)
at callWithDebugContext (VM263 vendor.js:15482)
at Object.debugCreateRootView [as createRootView] (VM263 vendor.js:14755)
at ComponentFactory_.create (VM263 vendor.js:11652)
at ComponentFactoryBoundToModule.create (VM263 vendor.js:4404)
at ViewContainerRef_.createComponent (VM263 vendor.js:11849)
at IonicApp.ngOnInit (VM263 vendor.js:54207)
at checkAndUpdateDirectiveInline (VM263 vendor.js:12785)
at checkAndUpdateNodeInline (VM263 vendor.js:14309)
at checkAndUpdateNode (VM263 vendor.js:14252)
如何完美实现此功能。
谢谢。
答案 0 :(得分:0)
将导入js放在src / index.html标头标签中,在build / polyfills.js和build / main.js(它们在body标签中)之前;
我创建了一个带有var测试的文件src / assets / test.js,先导入src / index.html,然后再导入src / app / app.component.ts中,然后声明define var test;。
test.js
var test = "Hello";
index.html
...
<link rel="icon" type="image/x-icon" href="assets/icon/favicon.ico">
<link rel="manifest" href="manifest.json">
<meta name="theme-color" content="#4e8ef7">
<!-- cordova.js required for cordova apps -->
<script src="cordova.js"></script>
<script src="assets/js/test.js"></script>
... app.componet.ts
declare var test;
@Component({
templateUrl: 'app.html'
})
export class MyApp {
@ViewChild(Nav) nav: Nav;
constructor(private statusbar : StatusBar, splashScreen: SplashScreen) {
alert(test);
...