javascript - 调用 toastr onShown 事件中的其他函数

标签 javascript angular typescript angular6 angular-toastr

我有下面的 toastr 代码

    toastr.success("<br /><br /><button type='button' id='confirmationRevertYes' class='btn clear'>Yes</button>",'delete item?',
      {
          closeButton: false,
          allowHtml: true,
          onShown: function (toast) {
              $("#confirmationRevertYes").click(function(){
                hidepanel(); // not working
                this.hidepanel(); // not working
              });
            }
      });

我在外面有一个功能

hidepanel(){
}

当尝试调用内部 toastr onShown 方法时,它会抛出错误

hidepanel does not exist on type 'HTMLElement'.

这怎么行?

谢谢

最佳答案

假设您有一个函数调用 hidepanel,请使用 => 表达式

toastr.success("<br /><br /><button type='button' id='confirmationRevertYes' class='btn clear'>Yes</button>",'delete item?',
  {
      closeButton: false,
      allowHtml: true,
      onShown: (toast) => {
          $("#confirmationRevertYes").click(() =>{ 
            this.hidepanel();  
          });
        }
  });

关于javascript - 调用 toastr onShown 事件中的其他函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52517249/

相关文章:

javascript - Angular 2 模块.id

javascript - ngx-Bootstrap 中的月份范围选择器

javascript - 如果在同一文件中,指令的 Angularjs 服务未知

javascript - jquery,javascript,html div相关查询

javascript - JQuery 工具多重叠加

php - 嵌入在 html 中的 JavaScript 未加载

angularjs - p-fileUpload 不能多次启动

reactjs - 用于服务器端渲染的 create-react-app typescript

javascript - Ionic 2 不更新 UI

javascript - JQuery/Javascript 翻页