简体   繁体   English

ionic2 / angular2-在打字稿中访问外部文件中的对象

[英]ionic2/angular2 - Access an object in an external file in typescript

I am building a mobile app using ionic2. 我正在使用ionic2构建一个移动应用程序。 For payments online i use a simple online payment service called Paystack. 对于在线支付,我使用一个称为Paystack的简单在线支付服务。

it works by including a js file in your webpage and then calling a function 它的工作原理是在您的网页中包含一个js文件,然后调用一个函数

<script>
  function payWithPaystack(){
    var handler = PaystackPop.setup({
      key: 'UNIQUE_KEY_HERE',
      email: 'customer@email.com',
      amount: 10000,
      ref: "UNIQUE TRANSACTION REFERENCE HERE",
      metadata: {
         custom_fields: [
            {
                display_name: "Mobile Number",
                variable_name: "mobile_number",
                value: "+2348012345678"
            }
         ]
      },
      callback: function(response){
          alert('success. transaction ref is ' + response.reference);
      },
      onClose: function(){
          alert('window closed');
      }
    });
    handler.openIframe();
  }
</script>

I am trying to port this to my ionic app. 我正在尝试将此移植到我的离子应用程序。 The problem is that it doesn't recognise PaystackPop even though i included the js file in the index.html. 问题是,即使我将js文件包含在index.html中,它也无法识别PaystackPop

How can i resolve this? 我该如何解决? I'm guessing i have to somehow import PaystackPop the way i import other classes, but i have no idea how to go about this. 我猜想我必须以某种方式导入PaystackPop ,就像我导入其他类一样,但是我不知道如何去做。 Any advice? 有什么建议吗?

I figured it out. 我想到了。 All i had to do was declare PaystackPop at the top of the file. 我要做的就是在文件顶部声明PaystackPop

import { Component } from '@angular/core';
import { NavController, ViewController, ToastController } from 'ionic-angular';

declare var PaystackPop: any;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM