【问题标题】:Uncaught TypeError: is not a function in RazorPay callback未捕获的 TypeError:不是 RazorPay 回调中的函数
【发布时间】:2021-06-06 03:25:40
【问题描述】:

我在我的打字稿类中有这样定义的处理程序

  "handler": function (response) {
              this.sendUserStatus();
  },
 

但是当我调用 this.sendUserStatus(); 我得到以下错误

Uncaught TypeError: this.sendUserStatus is not a function

如何调用 this.sendUserStatus()?

【问题讨论】:

    标签: angular typescript razorpay


    【解决方案1】:

    使用箭头函数:

    "handler": (response) => this.sendUserStatus()
    

    否则,如果您使用 function 关键字,this 上下文将丢失。

    另外,请注意您正在使用 Angular,并且此类事件可能不会被 ngZone 修补。您应该重新进入该区域:

    constructor(private ng: NgZone) {}
    
    "handler": this.ng.run(() => (response) => this.sendUserStatus())
    

    【讨论】:

    • 谢谢...:) 它奏效了。也感谢您指点 ngZone
    • Kruijit 知道为什么我会得到这个“服务工作者”,这肯定是你的网络应用清单中的字典。在我的控制台中
    • @NidhinPaul 尝试清除开发工具/应用程序选项卡中的站点数据。或使用隐身窗口
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-01-07
    • 1970-01-01
    • 1970-01-01
    • 2020-11-03
    • 2017-05-15
    • 2020-04-15
    • 1970-01-01
    相关资源
    最近更新 更多