【问题标题】:how do I add a page link in the ok button of Swal in Angular?如何在 Angular 的 Swal 的确定按钮中添加页面链接?
【发布时间】:2021-12-06 13:57:07
【问题描述】:

这是我的 html 文件

<button (click)="pay()">Add to Cart</button>

这是我的 ts 文件

pay(){
    Swal.fire(
      `Congratulations!!????`,
      `<h3>The item has been added to the cart!!<h3>`,
      'success');
  }

所以,当我点击OK(这里是成功)时,我希望用户重定向到网站的购物车页面。如何添加链接?

【问题讨论】:

标签: javascript html angular typescript sweetalert


【解决方案1】:
pay(){
    Swal.fire(
      `Congratulations!!?`,
      `<h3>The item has been added to the cart!!<h3>`,
      'success').then(() => {
            this.router.navigate(['/yourCartPage']);
    })
}

【讨论】:

    【解决方案2】:

    只需使用 JavaScript 承诺。将 then 方法放在 swal 函数之后。我们不需要使用计时器功能。例如:

      swal({
          title: 'Request Delivered',
          text: 'You can continue with your search.',
          type: 'success'
        }).then(function() {
            window.location = "redirectURL";
        })
    

    谢谢

    【讨论】:

    • 这给了我 window.location 上的错误,因为:Type 'string' is not assignable to type 'Location'.ts(2322) (property) location: Location.
    猜你喜欢
    • 1970-01-01
    • 2015-09-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-01-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多