异步收到响应后如何更改文本?
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(); });
更新(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>
我的答案与 Angular2 无关,而是一个要记住的简单解决方案,在 Swal 选项中你可以这样做
confirmButtonText: (() => {
if (your_data) {
return "something"
} else return "something else"
})()