Sweetalert2 - 动态更改显示的文本 - Angular2

问题描述 投票:0回答:2

异步收到响应后如何更改文本?

  var swText = "<h3>Importiranje kvota, molimo sačekajte...</h3>";
  swal({ html: swText });
  swal.showLoading();
  this.koloService.importExcelFileWithOdds(this.brojKola, fileList)
      .subscribe(
          data => { swText = "<h3>Importiranje završeno!</h3>"; swal.hideLoading(); },
          error => {  swText = "<h3>Importiranje završeno!</h3>"; swal.hideLoading(); });

另外,在收到服务器响应后如何隐藏进度警报? 导入数据时,进度警报如下所示:

在我收到服务器的响应后,进度警报不会隐藏,只有一个“确定”按钮可以关闭警报 - 我希望它在收到服务器的响应后立即关闭。

javascript angular sweetalert2
2个回答
5
投票

更新(2022):使用

Swal.update()
方法:

Swal.fire('After mignight I will turn into a pumpkin')
swal.showLoading()

// change the title after 2 seconds
setTimeout(() => {
  Swal.update({ title: 'I am a pumpkin now!' })
  Swal.hideLoading()
}, 2000)
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>


有各种 getter 用于访问 SweetAlert2 的不同部分:https://sweetalert2.github.io/#methods

您正在寻找

Swal.getTitle()
:

Swal.fire('After mignight I will turn into a pumpkin')
swal.showLoading()

// change the title after 2 seconds
setTimeout(() => {
  Swal.getTitle().textContent = 'I am a pumpkin now!'
  Swal.hideLoading()
}, 2000)
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>


0
投票

我的答案与 Angular2 无关,而是一个要记住的简单解决方案,在 Swal 选项中你可以这样做

confirmButtonText: (() => {
   if (your_data) {
     return "something"
   } else return "something else"
})()
© www.soinside.com 2019 - 2024. All rights reserved.