我可以从导入的外部js文件的函数的回调函数中调用函数吗

时间:2018-09-06 11:08:49

标签: javascript angular typescript

我已经在我的component.ts文件中导入了一个外部js文件,并使用如下所示的功能。

 declare var getpaidSetup: any;
import "../../../../assets/js/rave/test"; 

pay_order_payment_card_on_delivery(payment_mode_cash){
    this.helper.myLoading = true;
    let json = {
        user_id: this.user_id,
        server_token: this.server_token,
        order_payment_id: this.helper.user_cart.order_payment_id,
        payment_id: this.selected_payment_gateway,
        is_payment_mode_cash: payment_mode_cash
    }
    this.helper.http.post(this.helper.POST_METHOD.PAY_ORDER_PAYMENT, json).map((res_data: Response) => res_data.json()).subscribe(res_data => {
        console.log('res_data');
        console.log(res_data);

        if(res_data.success){
            if(res_data.remaining_payment > 0){
                var chargeResponse = "",
                trxref = "FDKHGK" + Math.random(),
                pubkey = "FLWPUBK-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa-X";
                let x = new getpaidSetup({
                    customer_email: "textaiwo@yahoo.com", 
                    amount: res_data.remaining_payment,
                    currency: "NGN",
                    country: "NG",
                    custom_description:"",
                    custom_title: "The Start",
                    txref: trxref,
                    PBFPubKey: pubkey,
                    onclose: function(response) {
                        console.log("response")
                    },
                    callback: function(response) {
                      console.log("This is the returnedesponse returned after a charge", response);

                      if(response.tx.chargeResponseCode == "00" || response.tx.chargeResponseCode == "0") {
                        console.log('payment_gateway successful');
                        console.log(response);

                        this.fluterwave_success();
                    } else {
                    }
                    x.close();
                }
            });

            }else{
                this.create_order_service();
            }
        } else {
            this.helper.myLoading = false;
            this.helper.data.storage = {
                "message": this.helper.ERROR_CODE[res_data.error_code],
                "class": "alert-danger"
            }
            this.helper.message();
        }
    },
    (error: any) => {
        this.helper.myLoading = false;
        this.helper.http_status(error)
    });
  }

    fluterwave_success(){
        console.log('fluterwave_success')
     }

即使该函数存在,我也会犯错,就像未定义一样,我也得到响应日志,但函数未调用,为什么我不能调用fluterwave_success函数并给出错误信息

如下所示的错误

order_payment.component.ts:448 Uncaught TypeError: this.fluterwave_success is not a function
at Object.callback (order_payment.component.ts:448)
at Object.message_handlers.opop (test.js:100)
at test.js:178
at ZoneDelegate.invokeTask (zone.js:265)
at Zone.runTask (zone.js:154)
at ZoneTask.invoke (zone.js:335)

0 个答案:

没有答案